In the corner of my basement is a media server running Windows 2012 core. I never have to log into it, I never have to update it, I never have to do much with it. The server simply runs, which is the whole point of core right? Unfortunately there was another thing that I thought I never had to maintain … backup (which happens to be?something?else my server does). That’s supposed to work automatically with no human intervention right? And for some reason the backup drives aren’t being detected. Ugh, now I have to shut it down and connect monitors and stuff and fix it. Life is so hard in Mike’s first world basement.
This presented another?dilemma. How does one remote into a server with powershell to run the shutdown command? (No domain so shutdown /m \\SERVER doesn’t work). Sure, I could just hit the power button but that’s not proper. Plus, remoting in with powershell is pretty damn easy, as most everything in powershell is.
1. Make sure you trust your server. Run this to add it to your trusted hosts.
Set-Item wsman:\localhost\Client\TrustedHosts SERVERNAME -Concatenate -Force
If you don’t trust the server you’ll get an error like this.
Connecting to remote server SERVER failed with the following error message : The client
cannot connect to the destination specified in the request. Verify that the service on the destination is running and
is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination,
most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to
analyze and configure the WinRM service: “winrm quickconfig”. For more information, see the
about_Remote_Troubleshooting Help topic.
2. Now you can remote in, but wait, you’re in a workgroup so it’s not going to just let you in willy nilly. But you?can?pass it your credentials easy enough.
Enter-PSSession -ComputerName SERVERNAME -Credential “SERVER\USER”
3. It will ask you for your password. Once in you?can?shutdown the server with the following command.
shutdown /t 0 /f /s
/t 0 = shutdown immediately.
/f = force
/s = shutdown. You can use /r to reboot instead of shutdown
4. I like to run a ping -t to watch for it to go down as well.
ping X.X.X.X -t or ping servername -t