0

Webサービスを介して呼び出すc#からPowerShellコマンドを実行しています

これはコマンドですSet-MailboxAutoReplyConfiguration -identity

これが私のコードです。

string command = "Set-MailboxAutoReplyConfiguration -identity " + user;

Webサービスを通過するユーザー。

ただし、実行するとこのエラーが発生します。

System.Management.Automation.RemoteException: The term 'Set-MailboxAutoReplyConfiguration -identity babbey' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

コマンドの前後で&#39がどこから来ているのかわかりません。ただし、+user部分を削除すると正常に動作します。だから私の問題は、コマンド変数にある変数です。

4

1 に答える 1

2

を使用する場合はPowerShell.AddCommand、コマンド名のみを指定します(例:)Set-MailboxAutoReplyConfiguration。次に、コマンドでAddParameterを呼び出して、パラメーターを追加します。例:

var ps = PowerShell.Create();
ps.AddCommand("Set-MailboxAutoReplyConfiguration");
ps.AddParameter("Identity", user);
于 2012-09-05T21:08:57.533 に答える