Running a powershell command remotely as a different user

Recently we had an issue where we couldn’t remote on to a servers that were unpatched with the May security patches from machines that had been patched (See my previous blog: http://www.risual.com/2018/06/11/rdp-authentication-error-due-to-the-credssp-encryption-oracle-remediation-error). Unfortunately one of these happened to be an off domain workgroup server so we couldn’t simply run the powershell but needed to provide credentials, here’s how to do that!

$ComputerName = “ComputerWithoutPatchOffDomain”
$Credential = “administrator”
(Get-WmiObject -class Win32_TSGeneralSetting -Namespace root\cimv2\terminalservices -ComputerName $ComputerName -Credential $Credential -Filter “TerminalName=’RDP-tcp'”).UserAuthenticationRequired

You can run pretty much any command there but that one links back to the NLA setting from my previous post.  The important bit is the -Credential $Credential bit – it will pop up and ask for the password.

Hope it helps!

About the author