The default is 0 which means do a simple logoff. The Win32Shutdown method can accept parameters. PS C:\> Get-WmiObject win32_operatingsystem -ComputerName Quark | Invoke-WMIMethod -name Win32Shutdown I found it just as easy to pipe a WMI object from Get-WMIObject to Invoke-WMIMethod: I recommend using Invoke-WMIMethod because it supports -WhatIf and -Confirm. Be aware this will force applications to close with the potential loss of unsaved work.Īnother option for rebooting or even logging off is to use the Win32_OperatingSystem WMI Class and the Win32ShutDown method. ![]() However, you can force a reboot using - what else? - the -force parameter. The Restart-Computer cmdlet will fail, if a logon session is detected. I'll get prompted for the password, but then this credential will be used for every computer in the list. PS C:\> restart-computer (get-content c:\work\computers.txt) -credential "mycompany\administrator" PS C:\> restart-computer (get-content c:\work\computers.txt)īecause the cmdlet is using WMI objects and methods under the hood you can specify alternate credentials, either a saved credential object or a user name: ![]() PS C:\> restart-computer "server01","server02","server03" -whatifīy the way, here's how you could shut down a list of computers: This is especially helpful if I'm rebooting a bunch of servers: Although I didn't really I took advantage of the -WhatIf parameter to verify my command.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |