【发布时间】:2014-01-10 07:01:10
【问题描述】:
如果运行 lync powershell 命令“Get-CsUser”,我会遇到异常。我正在使用管理员和具有 lync powershell 的机器上运行应用程序。
System.Management.Automation.CommandNotFoundException:术语 'Get-CsUser' 未被识别为 cmdlet、函数的名称, 脚本文件或可运行的程序。检查名称的拼写,或 如果包含路径,请验证路径是否正确并重试。 在 System.Management.Automation.CommandDiscovery.LookupCommandInfo(字符串 commandName, CommandOrigin commandOrigin) 在 System.Management.Automation.CommandDiscovery.LookupCommandProcessor(字符串 commandName, CommandOrigin commandOrigin, Nullable`1 useLocalScope)
在 System.Management.Automation.Runspaces.Command.CreateCommandProcessor(ExecutionContext executionContext, CommandFactory commandFactory, Boolean addToHistory) 在 System.Management.Automation.Runspaces.LocalPipeline.CreatePipelineProcessor() 在 System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper() 在 System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()
示例代码:
using (Runspace runspace = RunspaceFactory.CreateRunspace(initial))
{
//// open it
runspace.Open();
using (PowerShell ps = PowerShell.Create())
{
ps.Runspace = runspace;
ps.AddScript("import-module 'C:\\Program Files\\Common Files\\Microsoft
ps.AddCommand("Get-CsUser");
Collection<PSObject> results = ps.Invoke();
foreach (PSObject obj in results)
{
stringBuilder.AppendLine(obj.ToString());
}
runspace.Close();
}
}
有什么建议可以解决这个问题???
【问题讨论】:
标签: c# powershell lync