
WMIとPowerShellのみを使用して(リモート処理ではなく)Windowsコマンドをリモートで実行し、出力をキャプチャします。
WMIとPowerShellのみに依存するWindows向けのリモート実行ツール。
PowerShell Remoting、WinRM、PsExecに依存することなく、コンソールコマンドをリモートで実行し、かつ stdout/stderrストリームをキャプチャします。
以下の例は、WmiExecがパイプラインからコマンド文字列を値として受け取る方法を示しています。
PS C:\ "Get-ChildItem C:\" | .\WmiExec.ps1 -ComputerName "server1"
Running the following command on: server1...
Get-ChildItem C:\
PID: 5580 - Waiting for remote command to finish...
PID: 5580 - Waiting for remote command to finish...
Result...
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 28.06.2018 15:16 PerfLogs
d-r--- 09.09.2019 15:19 Program Files
d-r--- 07.10.2019 08:36 Program Files (x86)
d-r--- 10.10.2019 10:51 Users
d----- 10.10.2019 16:00 Windows
以下の例は、返されるオブジェクトの型を示しています。
PS C:\ $result = .\WmiExec.ps1 -ComputerName "server1" -Command "Get-ChildItem C:\"
Running the following command on: server1...
Get-ChildItem C:\
PID: 5580 - Waiting for remote command to finish...
PID: 5580 - Waiting for remote command to finish...
Result...
PS C:\ $result.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
Twitter https://twitter.com/OneScripter
System Frontierを使えば、RBACを活用したPowerShellスクリプト用のWeb GUIを作成するなど、さらにクールなことができます。 https://systemfrontier.com/powershell