The ability to programmatically restart a computer allows administrators to perform many computer management tasks remotely.
For example, if you create a script to install software or make a configuration change that requires restarting a computer, you can include the restart command in the script and perform the entire operation remotely.
The Reboot method can be used to restart a computer.
Like the Win32Shutdown method, the Reboot method requires the user whose security credentials are being used by the script to possess the Shutdown privilege.
Example
Do not run below example code just to see what happens next. Many methods seriously affect your system. Always make sure you actually understand what the method and the code do.
$query = 'Select * From Win32_OperatingSystem'
Invoke-CimMethod -Query $query -MethodName Reboot |
Add-Member -MemberType ScriptProperty -Name ReturnValueFriendly -Passthru -Value {
switch ([int]$this.ReturnValue)
{
0 {'Success'}
default {"Unknown Error $_"}
}
}
To run this method on one or more remote systems, use New-CimSession
:
$session = New-CimSession -ComputerName $ComputerName -Credential $Credential
$query = 'Select * From Win32_OperatingSystem'
Invoke-CimMethod -Query $query -MethodName Reboot -CimSession $session |
Add-Member -MemberType ScriptProperty -Name ReturnValueFriendly -Passthru -Value {
switch ([int]$this.ReturnValue)
{
0 {'Success'}
default {"Unknown Error $_"}
}
}
Remove-CimSession -CimSession $session
Learn more about
Invoke-CimMethod
and invoking WMI methods.
Syntax
uint32 Reboot();
Parameters
The method takes no arguments.
Return Value
Returns a value of type UInt32. Return values:
$returnValues = @{
0 = 'Success'
}
See Also
Additional methods implemented by Win32_OperatingSystem:
SetDateTime()
SetDateTime() allows the computer date and time to be set.
Shutdown()
Shutdown() unloads programs and DLLs to the point where it is safe to turn off the computer.
Win32Shutdown()
Win32Shutdown() provides the full set of shutdown options supported by Windows operating systems.
Win32ShutdownTracker()
Win32ShutdownTracker() provides the same set of shutdown options supported by Win32Shutdown() but also allows you to specify comments, a reason for shutdown, or a timeout.
Requirements
To use Win32_OperatingSystem, the following requirements apply:
PowerShell
Get-CimInstance
was introduced with PowerShell Version 3.0, which in turn was introduced on clients with Windows 8 and on servers with Windows Server 2012.
If necessary, update Windows PowerShell to Windows PowerShell 5.1, or install PowerShell 7 side-by-side.
Operating System
Win32_OperatingSystem was introduced on clients with Windows Vista and on servers with Windows Server 2008.
Namespace
Win32_OperatingSystem lives in the Namespace Root/CIMV2. This is the default namespace. There is no need to use the -Namespace parameter in Get-CimInstance
.
Implementation
Win32_OperatingSystem is implemented in CIMWin32.dll and defined in CIMWin32.mof. Both files are located in the folder C:\Windows\system32\wbem
:
explorer $env:windir\system32\wbem
notepad $env:windir\system32\wbem\CIMWin32.mof