C# 言語を使用して、リモート マシンでいくつかの Active Directory クエリを実行したいと考えています。
PowerShell ps = PowerShell.Create();;
ps.AddScript(@"$Session = New-PSsession -Computername com1");
ps.AddScript(@"Invoke-Command -Command {Import-Module ActiveDirectory} -Session $Session");
ps.Invoke();
最初の実行後に上記のコマンドの実行をスキップし、プログラムが終了するまでセッションを維持する必要があります。確立された同じセッションでさらにスクリプトを実行するのを手伝ってください。
正確には、プログラム全体で一度だけセッションを作成したい.Thanks