This script can be used to install or upgrade the DellBIOSProvider Powershell module (used to manage the BIOS configuration of Dell devices from Powershell).
Validation is performed to ensure that this module is only installed for Dell devices; if the system is not Dell it will not be installed.
# This module will install the Dell BIOS Provider module for PowerShell.
# Only Dell computers are supported, other manufacturers will be skipped.
#Requires -RunAsAdministrator
Write-Host -ForegroundColor Gray 'Installing DellBIOSProvider Module'
# Get the system information
Write-Host -ForegroundColor Gray 'Getting hardware manufacturer...'
try {
$manufacturer = (Get-CimInstance -ClassName Win32_ComputerSystem -ErrorAction Stop | Select-Object -ExpandProperty Manufacturer -ErrorAction Stop)
Write-Host -ForegroundColor Gray "Manufacturer is $manufacturer"
}
catch {
$message = $_.Exception.message
Write-Error 'Could not get CIM class Win32_ComputerSystem, cannot continue without knowing if this is made by Dell or not:'
throw $message
}
# Check if this is a Dell computer
if ( $manufacturer -notlike '*Dell*') {
Write-Host -ForegroundColor Green 'System manufacturer does not match Dell, module will not be installed.'
exit
} else {
Write-Host -ForegroundColor Gray 'System appears to be made by Dell. Continuing with module installation...'
}
# Check if module has already been installed
Write-Host -ForegroundColor Gray 'Checking module installation status...'
try {
$module = Get-Module -ListAvailable -Name DellBIOSProvider -ErrorAction Stop
if ( $module.Version ) {
if ([version]$module.Version -lt [version]'2.3.0') {
Write-Host -ForegroundColor Green "DellBIOSProvider module version $($module.Version) is already installed - Updating module"
} else {
Write-Host -ForegroundColor Green "DellBIOSProvider module version $($module.Version) is already installed and up to date; nothing to do"
exit
}
Write-Host -ForegroundColor Yellow 'Attempting module upgrade...'
try {
Update-Module -Name DellBIOSProvider -ErrorAction Stop -Force -Confirm:$False
Write-Host -ForegroundColor Green 'DellBIOSProvider module upgrade success'
}
catch {
Write-Host -ForegroundColor Red 'Error upgrading module; trying reinstall of module'
try {
Uninstall-Module -Name DellBIOSProvider -ErrorAction Stop -Force -Confirm:$False
Install-Module -Name DellBIOSProvider -ErrorAction Stop -Force -Confirm:$False
Write-Host -ForegroundColor Green 'DellBIOSProvider module upgrade success'
}
catch {
Write-Host -ForegroundColor Red 'Error upgrading module'
}
}
exit
} else {
Write-Host -ForegroundColor Yellow 'DellBIOSProvider module not installed yet, installation will proceed after requirements are checked'
}
}
catch {
Write-Host -ForegroundColor Yellow 'DellBIOSProvider module not installed yet, installation will proceed after requirements are checked'
}
Write-Host -ForegroundColor Gray 'Validating NuGet PackageProvider is available...'
try {
$version = (Get-PackageProvider -ListAvailable -Name NuGet -ErrorAction Stop).version
if ( $version -ge [Version]'2.8.5.201' ) {
Write-Host -ForegroundColor Green 'NuGet PackageProvider available; version meets requirements'
} else {
Write-Error 'NuGet package is too old to support the module installation. Update the module before trying again.'
exit
}
}
catch {
$message = $_.Exception.message
Write-Error 'Error checking NuGet package provider, it is probably not installed yet:'
throw $message
}
# Validate the module is allowed to be installed from PSGallery
Write-Host -ForegroundColor Gray 'Validating PSGallery installation is allowed...'
try {
$gallery = Get-PSRepository -Name PSGallery -ErrorAction Stop
if ( !$gallery.Registered ) {
Write-Error 'PSGallery must be registered before continuing'
exit
} else {
Write-Host -ForegroundColor Green 'PSGallery is registered'
}
if ( !$gallery.Trusted ) {
try {
Write-Host -ForegroundColor Gray 'Trusting PSGallery repository'
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
Write-Host -ForegroundColor Green 'Trusted PSGallery repository'
}
catch {
Write-Error 'PSGallery must be trusted before continuing'
exit
}
} else {
Write-Host -ForegroundColor Green 'PSGallery is trusted'
}
}
catch {
$message = $_.Exception.message
Write-Error 'Error checking PSGallery, it is probably not installed for some reason:'
throw $message
}
Write-Host -ForegroundColor Yellow 'All requirements met, installing the module...'
try {
Install-Module -Name DellBIOSProvider -ErrorAction Stop -Force -Confirm:$False
Write-Host -ForegroundColor Green 'DellBIOSProvider module is now installed'
}
catch {
$message = $_.Exception.message
Write-Error 'Error installing module:'
throw $message
}