Last active
July 10, 2020 13:01
-
-
Save dpo007/77a69e5c76d8d858f163d23c9e05d973 to your computer and use it in GitHub Desktop.
PowerShell :: Enables or disables Intel virtualization settings in various Lenovo BIOSs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[string]$BiosPass = 'YerPassword', | |
[switch]$Disable | |
) | |
$vendor = (Get-WMIObject -Class Win32_ComputerSystemProduct).Vendor | |
if ($vendor.ToUpper() -ne 'LENOVO') { | |
Write-Host ('This is intended for use with Lenovo devices only. "Vendor" returned "{0}", exiting.' -f $vendor) | |
Exit 666 | |
} | |
# Known working models: | |
# | |
# M900 | |
# M910q | |
# M93p | |
# T450s | |
# T460s | |
# T470s | |
# | |
# Script is pretty dynamic, so it may work with other/future models as well (it may also break everything). | |
Write-Host ('Model: {0}' -f (Get-WMIObject -Class Win32_ComputerSystemProduct).Version) | |
try { | |
# Check Virtualization Settings | |
$settingList = Get-WmiObject -Namespace 'root\wmi' -Class Lenovo_BiosSetting | |
$settingsToChange = $settingList | Where-Object { | |
$_.CurrentSetting -like "*Virtualization*" ` | |
-or $_.CurrentSetting -like "VT*d*" ` | |
-or $_.CurrentSetting -like "TxT*" | |
} | Select-Object -ExpandProperty CurrentSetting | |
} catch [Exception] { | |
Write-Host ('Error getting settings: {0}' -f $_.Exception.Message) | |
Exit 666 | |
} | |
try { | |
# Set specific BIOS settings when a BIOS password is set | |
$interface = Get-WmiObject -Namespace 'root\wmi' -Class Lenovo_SetBiosSetting | |
foreach ($settingToChange in $settingsToChange) { | |
Write-Host "Current setting: $settingToChange" | |
if ($settingToChange.ToLower().Contains('enabled') -or $settingToChange.ToLower().Contains('disabled')) { | |
$state = 'Enabled' | |
if ($Disable) { | |
$state = 'Disabled' | |
} | |
} elseif ($settingToChange.ToLower().Contains('enable') -or $settingToChange.ToLower().Contains('disable')) { | |
$state = 'Enable' | |
if ($Disable) { | |
$state = 'Disable' | |
} | |
} else { | |
Write-Host 'Unrecognized BIOS setting options, aborting.' | |
Exit 666 | |
} | |
$settingName = $settingToChange.Split(',')[0] | |
Write-Host ('Setting "{0}" to {1}...' -f $settingName, $state) | |
$interface.SetBiosSetting("$settingName,$state,$BiosPass,ascii,us") | |
} | |
# Save any outstanding BIOS configuration changes | |
Write-Host "Saving changes to BIOS..." | |
$saveSettings = Get-WmiObject -Namespace 'root\wmi' -Class Lenovo_SaveBiosSettings | |
$saveSettings.SaveBiosSettings() | |
} catch [Exception] { | |
Write-Host ('Error applying settings: {0}' -f $_.Exception.Message) | |
Exit 666 | |
} | |
# Check Updated Virtualization Settings | |
Write-Host "Final settings:" | |
$settingList = Get-WmiObject -Namespace 'root\wmi' -Class Lenovo_BiosSetting | |
$settingList | Where-Object { | |
$_.CurrentSetting -like "*Virtualization*" ` | |
-or $_.CurrentSetting -like "VT*d*" ` | |
-or $_.CurrentSetting -like "TxT*" | |
} | Select-Object -ExpandProperty CurrentSetting |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment