
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 1.47 KB | hits: 55 | expires: Never
Starting Powershell elevated from PSExec (enable-psremoting)
psexec.exe \server cmd /c "echo . | powershell (-verb runas -argumentlist (enable-psremoting -force))"
$c = Get-Credential
$u = $c.UserName
$p = $c.GetNetworkCredential().Password
$path = "C:SysinternalsSuite"
& "$pathpsexec.exe" \server -u $u -p $p powershell.exe -Command "Enable-PSRemoting -Force"
$user = "youruser"
$p = Read-Host "Enter domain password for $adminuser"
cls
$expression1 = "enable-psremoting -force"
$commandBytes1 = [System.Text.Encoding]::Unicode.GetBytes($expression1)
$encodedCommand1 = [Convert]::ToBase64String($commandBytes1)
$expression2 = "Set-ExecutionPolicy remotesigned -Force”
$commandBytes2 = [System.Text.Encoding]::Unicode.GetBytes($expression2)
$encodedCommand2 = [Convert]::ToBase64String($commandBytes2)
$expression3 = "Restart-Service winrm”
$commandBytes3 = [System.Text.Encoding]::Unicode.GetBytes($expression3)
$encodedCommand3 = [Convert]::ToBase64String($commandBytes3)
foreach ($server in (get-content c:tempenablepsremotinglist.txt))
{
echo " "
echo "Running on $server"
echo "--------------------------------------- "
echo " "
psexec.exe \$server -h -u no$user -p $p cmd /c "echo . | powershell -EncodedCommand $encodedCommand1"
psexec.exe \$server -h -u no$user -p $p cmd /c "echo . | powershell -EncodedCommand $encodedCommand2"
psexec.exe \$server -h -u no$user -p $p cmd /c "echo . | powershell -EncodedCommand $encodedCommand3"
}