psexec の起動後にプロセス IDを取得するの続き
PSCommand と PowerShellを使用して、質問に対する回答を得る方法を知りたいです。
私は深みがあり、助けが必要です。これが私が最初に答えを翻訳することを考えたものであり、失敗した試みです。
private int GetRemoteProcessId()
{
string remoteFilename = "ExampleBatfile.bat";
string remoteDirectory = "C:\\ExampleDirectory";
string remoteUsername = "ExampleUsername";
string remotePassword = "ExamplePassword";
string remoteIp = "ExampleIP";
PowerShell ps = PowerShell.Create()
.AddScript($"psexec.exe \\{remoteIp} -accepteula -u {remoteUsername} -p {remotePassword} -s -i -d - w {remoteDirectory} {remoteFilename}" )
.AddCommand( "Select-String" ).AddParameter( "process ID (\\d+)" )
.AddCommand( "ForEach-Object" ).AddParameter( "{$_.Matches.Groups[1].Value}" );
Collection<PSObject> results = ps.Invoke();
int remoteProcessId = ( int )results.First().BaseObject;
return remoteProcessId;
}
私が望むのは、起動後に psexec を使用してリモートプロセスからプロセス ID を取得することだけです (回答された質問と同じです) - ただし、C# PSCommands を使用します。