Posted by: Richard Siddaway
when relevant content is
added and updated.
We’ve seen what information we can derive on the Operating System from Win32_OperatingSystem but is there anything we can actually do to our systems?
There are a handful of methods available to us – mainly to do with shutting down the system
PS> Get-WmiObject -Class Win32_OperatingSystem | Get-Member -MemberType Method | Format-Table Name, Definition -Wrap
Reboot System.Management.ManagementBaseObject Reboot()
SetDateTime System.Management.ManagementBaseObject SetDateTime(System.S
Shutdown System.Management.ManagementBaseObject Shutdown()
Win32Shutdown System.Management.ManagementBaseObject Win32Shutdown(System
.Int32 Flags, System.Int32 Reserved)
Win32ShutdownTracker System.Management.ManagementBaseObject Win32ShutdownTracker
(System.UInt32 Timeout, System.String Comment, System.UInt3
2 ReasonCode, System.Int32 Flags)
Details from http://msdn.microsoft.com/en-us/library/aa394239(VS.85).aspx but
Reboot will shutdown and restart the system. SetDatetime ssts computer date and time (shouldn’t be needed with Time synchronisation in the domain)
Shutdown unloads programs and dlls so computer can be turned off
Win32Shutdown gives us options
- 0 (0×0) = Log Off
- 4 (0×4) = Forced Log Off (0 + 4)
- 1 (0×1) = Shutdown
- 5 (0×5) = Forced Shutdown (1 + 4)
- 2 (0×2) = Reboot
- 6 (0×6) = Forced Reboot (2 + 4)
- 8 (0×8) = Power Off
- 12 (0xC) = Forced Power Off (8 + 4)
On Vista\Win2008 and above we can use
Win32ShutdownTracker to add a comment into the event log and and shutdown dialog box
We can use Win32Shutdown like this
$computer = Get-WmiObject -Class Win32_OperatingSystem -ComputerName .
If we put this into a loop and feed a set of computer names into it we can shut down our whole environment. Not a frequent occurrence – but one I needed to do recently when moving a datacentre.