Skip to content

Instantly share code, notes, and snippets.

@zachbonham
Created May 8, 2012 14:57
Show Gist options
  • Save zachbonham/2635944 to your computer and use it in GitHub Desktop.
Save zachbonham/2635944 to your computer and use it in GitHub Desktop.
invoke-remoteexpression
function invoke-remoteexpression($computer = “\\$ENV:ComputerName”, [ScriptBlock] $expression = $(throw “Please specify an expression to invoke.”), [switch] $noProfile , $username, $password)
{
$commandLine = “echo . | powershell “
if($noProfile)
{
$commandLine += “-NoProfile “
}
<#
some commands may cause encoding problems so we base64.
#>
$commandBytes = [System.Text.Encoding]::Unicode.GetBytes($expression)
$encodedCommand = [Convert]::ToBase64String($commandBytes)
$commandLine += “-EncodedCommand $encodedCommand”
psexec /acceptEula -u $username -p $password $computer cmd /c $commandLine
}
@zachbonham
Copy link
Author

Completely stole this from somewhere on the intertron and I don't remember where.
Yes, that is the venerable PSEXEC we are relying on for initial configuration of the remote server. Its assumed your an administrator on the remote machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment