繁体   English   中英

从c#webservice运行powershell命令

[英]running powershell command from c# webservice

我正在运行来自c#的powershell命令,我通过web服务调用它

这是命令Set-MailboxAutoReplyConfiguration -identity

这是我的代码。

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

我通过webservice的用户。

但是,当我运行它时,我收到此错误。

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来自我命令之前和之后的位置。 但是,如果我取出+用户部分,它可以正常工作。 所以我的问题是命令变量中的变量。

如果使用PowerShell.AddCommand ,则只需指定命令名称,例如Set-MailboxAutoReplyConfiguration 然后在命令上调用AddParameter来添加参数,例如:

var ps = PowerShell.Create();
ps.AddCommand("Set-MailboxAutoReplyConfiguration");
ps.AddParameter("Identity", user);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM