.NET フレームワークのProcessおよびProcessStartInfoクラスを使用して、プロセスを作成および制御できます。Windows PowerShell を使用して .NET オブジェクトをインスタンス化できるため、プロセスのほぼすべての側面を制御する機能を PowerShell 内から利用できます。
dir
コマンドをプロセスに送信する方法は次cmd.exe
のとおりです (これを .ps1 ファイルにラップしてから、スクリプトを実行してください)。
$psi = New-Object System.Diagnostics.ProcessStartInfo;
$psi.FileName = "cmd.exe"; #process file
$psi.UseShellExecute = $false; #start the process from it's own executable file
$psi.RedirectStandardInput = $true; #enable the process to read from standard input
$p = [System.Diagnostics.Process]::Start($psi);
Start-Sleep -s 2 #wait 2 seconds so that the process can be up and running
$p.StandardInput.WriteLine("dir"); #StandardInput property of the Process is a .NET StreamWriter object