Shutdown

Unloads programs and DLLs to the point where it is safe to turn off the computer.

Computers occasionally need to be removed from the network, perhaps for scheduled maintenance, because the computer is not functioning correctly, or to complete a configuration process.

For example, if a DHCP server is handing out erroneous IP addresses, you might want to shut the computer down until a service technician can be dispatched to fix the problem.

If you suspect that a security breach has occurred, you might need to shut down certain servers to ensure that they cannot be accessed until the security issue has been resolved.

Some configuration operations (such as changing a computer name) require you to restart the computer before the change takes effect.

This method immediately shuts the computer down, if possible. The system stops all running processes, flushes all file buffers to the disk, and then powers down the system. The calling process must have the SE_SHUTDOWN_NAME 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 Shutdown |
  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 Shutdown -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 Shutdown();

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:

Reboot()

Reboot() shuts down and then restarts the computer system.

SetDateTime()

SetDateTime() allows the computer date and time to be set.

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