1

I am in a "funny" situation where I have RDP credentials of about 200 servers, but none of them have Remote Powershell enabled.

I need a simple task: restart them all. But all I have is RDP (Administrator account) credentials (including: IP address, Username and Password of each server).

Is there any way from my laptop (Windows 10 if it's relevant) PowerShell/Command Prompt, I use that credential and run a PowerShell/Cmd command on those remote servers (in the future, I may need commands other than shutdown)?

3 Answers 3

1

As @ryanbolger mentioned, you can also do this with WMI. Jeffrey Hicks wrote a good article here. Get your list of servers either through Active Directory or from a text file. I'm using a text file as an example below as you haven't explicitly said you are using Active Directory. You also mentioned that you have the user names and passwords. If they are different, you will have to add that in for each server too. I'm assuming the username and password is the same for each one. MSDN is the link for the options in -argumentlist

$servers = get-content c:\listofservers.txt
$cred = get-credential
foreach ($server in $servers)
{
    Get-WmiObject -class win32_operatingsystem -ComputerName $server -credential $cred |
    Invoke-WMIMethod -name Win32Shutdown -credential $cred -argumentlist @(2)
}

Invoke-WMIMethod has the -whatif parameter available. I recommend using this to make sure it is going what you expect. Also, do this on a limited number of test machines before you roll it out to all 200 to make sure it is doing what you want it to do. In the link I posted, you can also use different options for -argumentlist if some servers don't reboot by default.

Thanks, Tim.

3
  • I am actually more interested in this solution. However, similar to @Ryan solution, I have this problem when making the call: Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA A quick search suggests it's firewall problem (also, I do not know if this requires Remote PS enabled). They are Azure VM, if the problem is Azure firewall, it's much easier, but if it's Windows firewall, then now the only way to access the servers are RDP ports).
    – Luke Vo
    Jan 29, 2017 at 19:29
  • Same error message when I use Restart-Computer Cmdlet too.
    – Luke Vo
    Jan 29, 2017 at 19:31
  • What version of Windows Server are you using? msdn.microsoft.com/en-us/library/aa822854(v=vs.85).aspx is how to setup your machines for WMI remote connections. Have the servers been specifically locked down to prevent this? It may be the firewall as you have mentioned. technet.microsoft.com/en-us/library/dn372891.aspx using test-netconnection you can check if ports are open.
    – Tim Haintz
    Jan 29, 2017 at 19:38
2

PsExec is pretty popular for running arbitrary commands against remote machines.

If you need something that is usable without downloading 3rd party software, the built-in shutdown.exe can do remote restarts as well. It even has a GUI if you use the -i flag. It doesn't let you specify alternate credentials though, so you'd have to run it in the context of the remote account's credentials with something like runas.

There are ways to do this with WMI as well, but shutdown.exe is probably easier.

1
  • Does PsExec need any special port to execute? I keep receiving "The network path was not found" although I can RDP into it manually. I tried the IP address with or without \\. PsExec.exe \\IP -u Administrator -p "<password>" shutdown -r
    – Luke Vo
    Jan 29, 2017 at 19:24
-1

So... two things. Rpc server unavailable is - if nothing has been fiddled with - a firewall is seminars them being azureVms I'd say it's 99% firewall issue. Question... are your vms isolated from each other? If not - log in to one of them and just use any of described methods from there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.