Windows+PowerShellでリモートPC上で、任意のコマンドを実行する。
RemotePC上で任意のコマンドを実行する
以下のPowerShellスクリプトをファイルとして保存する。
ここでは「RemoteCommand.ps1」とする。
Param( $computer, $username, $passwd, $command ) $password = ConvertTo-SecureString $passwd -asplaintext -force $cred = New-Object System.Management.Automation.PsCredential $username,$password invoke-command -ComputerName $computer -Credential $cred $command
使い方はこう。
> RemoteCommand.ps1 pc_name domain\username password_hoge {c:\bar\foo.bat}
{}で括られた中が、リモート先で実行される。
RemotePC上のコマンドプロンプト(cmd)を開く
以下のPowerShellスクリプトをファイルとして保存する。
ここでは「RemoteConsole.ps1」とする。
Param( $computer, $username, $passwd ) $password = ConvertTo-SecureString $passwd -asplaintext -force $cred = New-Object System.Management.Automation.PsCredential $username,$password enter-pssession -ComputerName $computer -Credential $cred