Created
May 8, 2012 14:57
-
-
Save zachbonham/2635944 to your computer and use it in GitHub Desktop.
invoke-remoteexpression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.