Change Lenovo BIOS Passwords with PowerShell 7.x

In PowerShell 7.x, the Get-WmiObject Cmdlet is no longer available. To achieve similar functionality, you'll need to utilize the Get-CimInstance Cmdlet instead.

Example Script:

$oldpw = "old123"
$newpw = "new123"
Get-CimInstance -Namespace root/WMI -ClassName Lenovo_WmiOpcodeInterface | Invoke-CimMethod -MethodName WmiOpcodeInterface -Arguments @{Parameter = "WmiOpcodePasswordType:pap" } | Out-Null

Get-CimInstance -Namespace root/WMI -ClassName Lenovo_WmiOpcodeInterface | Invoke-CimMethod -MethodName WmiOpcodeInterface -Arguments @{Parameter = "WmiOpcodePasswordCurrent01:$($oldpw)" } | Out-Null

Get-CimInstance -Namespace root/WMI -ClassName Lenovo_WmiOpcodeInterface | Invoke-CimMethod -MethodName WmiOpcodeInterface -Arguments @{Parameter = "WmiOpcodePasswordNew01:$($newpw)" } | Out-Null

$Status = Get-CimInstance -Namespace root/WMI -ClassName Lenovo_WmiOpcodeInterface | Invoke-CimMethod -MethodName WmiOpcodeInterface -Arguments @{Parameter = "WmiOpcodePasswordSetUpdate" }

if ($Status.Return -eq "Success") {
    "Password changed!"
} else {
    "Password change failed!"
}

This PowerShell script is used to change the password on a Lenovo device using the Windows Management Instrumentation (WMI) interface.

The script starts by defining two variables, $oldpw and $newpw, which store the old and new passwords respectively.

Next, the script uses the Get-CimInstance cmdlet to retrieve a WMI object representing the Lenovo device. The -Namespace parameter specifies the WMI namespace to use (root/WMI), and the -ClassName parameter specifies the WMI class to use (Lenovo_WmiOpcodeInterface).

The Invoke-CimMethod cmdlet is then used to call the WmiOpcodeInterface method on the retrieved WMI object. This method is called three times, each with different arguments, to perform the password change operation. The -Arguments parameter is used to pass a hashtable of arguments to the method. The Out-Null cmdlet is used to suppress the output of these commands.

The first call to WmiOpcodeInterface sets the password type to pap. The second call provides the current password, and the third call provides the new password.

After the password change operation is initiated, the script retrieves the status of the operation by calling WmiOpcodeInterface again with the WmiOpcodePasswordSetUpdate parameter. The returned status is stored in the $Status variable.

Finally, the script checks the Return property of the $Status object. If it equals "Success", the script outputs "Password changed!". Otherwise, it outputs "Password change failed!". This provides a simple way to verify whether the password change operation was successful.