1

次のコマンドを使用して、サーバーでPSexecを使用してpsremotingを有効にしようとしています。

psexec.exe \\server cmd /c "echo . | powershell (-verb runas -argumentlist (enable-psremoting -force))"

しかし、それは機能しません。二重引用符をめちゃくちゃにしていると思います。何か助けはありますか?

スネ:)

4

3 に答える 3

1

そのためにPSExecは必要ありません。PowerShell開発者のLeeによるこのスクリプトを確認してください。

http://poshcode.org/2141

于 2012-01-12T09:39:37.780 に答える
1

コメントありがとうございます!私はそれを行う方法を見つけました、そしてこれは完成したコードです:

$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:\temp\enablepsremotinglist.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"
}

これがいつか他の誰かの助けになることを願っています:)PS:これはあなたのadminpasswordをクリアテキストとして送信することを覚えておいてください。

于 2012-01-12T14:49:44.453 に答える
0

PowerShellを呼び出して昇格して実行しようとしているようです。これはリモートでは実行できない可能性があります...UACが有効になっていないマシン(2003サーバー)に対してこれを機能させることができました:

$c = Get-Credential
$u = $c.UserName
$p = $c.GetNetworkCredential().Password

$path = "C:\SysinternalsSuite"
& "$path\psexec.exe" \\server -u $u -p $p powershell.exe -Command "Enable-PSRemoting -Force"

何らかの理由で、シェルでEnterキーを数回押して、出力を吐き出し続け、最終的にプロンプ​​トに戻る必要がありました。どうしたのかわからない...

于 2012-01-11T20:54:52.827 に答える