PMPの流儀

我が家の流儀

我が家で気になったことを夫婦で取り上げていきます

MENU

Powershell でリモートPCでコマンドを実行する

ネットワーク環境下で、リモートPCに任意のコマンドを実行させる方法を紹介します。セキュリティに重大な穴を空けることになるので利用の際には十分に気を付けてさい。

準備

接続される側

Set-ExecutionPolicy RemoteSigned -Force

Set-WSManQuickConfig -Force

 

接続する側

Set-ExecutionPolicy RemoteSigned -Force

winrm quickconfig -force

Set-Item WSMan:\localhost\Client\TrustedHosts 接続先 -Force

 

リモートコマンド実行

Invoke-Command -ComputerName 接続先 -Credential $c {コマンド}