Powershell – run remote PowerShell/Cmd command with RDP credential, without Remote PS enabled

powershellremote desktopremote-accesswindows-command-prompt

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)?

Best Answer

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.