rebooting windows remotely with automation

If I wrote powershell all day every day I'm sure I'd get used to it and not find it so damn weird. But compared to just about every other language on the planet, Powershell is flat out odd. Switching back and forth between Powershell and traditional programming languages can be very difficult - the unintuitiveness of the syntax and base libraries means I have to relearn things over and over. Anyway... here's a rather simple thing that I'm sure I'll forget.

If you want to reboot a windows machine remotely and do it from the commandline with nothing but a username/password and computer name/ip address:

powershell.exe -Command "&{$pass = ConvertTo-SecureString 'YOURPASSWORD' -AsPlainText -Force ; $creds = New-Object System.Management.Automation.PSCredential ('.\Administrator', $pass) ; Restart-Computer -ComputerName YOURCOMPUTER -Wait -For WMI -Timeout 400 -Delay 2 -Credential $creds}"

Checkout the Restart-Computer page for more details and pick the right -For option for you.

Kelly Brownsberger

Kelly Brownsberger

I'm a passionate technologist, father, husband, and life long learner. I know how to laugh and try to always leave things better than I found them.
Photo by Blake Richard Verdoorn on Unsplash