Monday, June 28, 2010

Powershell Remote Execution (invoke-command) with Username Password Authentication

Powershell adds remote execution with 2.0. The commands are executed on the remote shell using the current local user or some other domain user specified using the -credential parameter.

Using just username and password is not as easy and of course not very secure because the password is saved in the script. Nevertheless sometimes you just have to and here is how.

$pass = convertto-securestring "P@ssW0rd" -asplaintext -force
$mycred = new-object -typename System.Management.Automation.PSCredential -argumentlist "DOMAIN\User",$pass
invoke-command remote-machine {get-process} -credential $mycred
Post a Comment