Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 术语';获取CsUser';无法识别为cmdlet、函数、脚本文件或可操作程序的名称_C#_Powershell_Lync - Fatal编程技术网

C# 术语';获取CsUser';无法识别为cmdlet、函数、脚本文件或可操作程序的名称

C# 术语';获取CsUser';无法识别为cmdlet、函数、脚本文件或可操作程序的名称,c#,powershell,lync,C#,Powershell,Lync,如果运行lync powershell命令“Get CsUser”,我将遇到以下异常。我正在使用administrator在具有lync powershell的计算机上运行应用程序 System.Management.Automation.CommandNotFoundException:术语 “Get-CsUser”未被识别为cmdlet、函数、, 脚本文件或可操作程序。检查名称的拼写,或 如果包含路径,请验证路径是否正确,然后重试。 在 System.Management.Automatio

如果运行lync powershell命令“Get CsUser”,我将遇到以下异常。我正在使用administrator在具有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,可为空的`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();
            }
}
使用(Runspace Runspace=RunspaceFactory.CreateRunspace(初始))
{
////打开它
Open();
使用(PowerShell ps=PowerShell.Create())
{
ps.运行空间=运行空间;
ps.AddScript(“导入模块”C:\\Program Files\\Common Files\\Microsoft
ps.AddCommand(“获取CsUser”);
收集结果=ps.Invoke();
foreach(结果中的PSObject对象)
{
stringBuilder.AppendLine(obj.ToString());
}
runspace.Close();
}
}

有什么建议可以解决这个问题吗?

我没有答案,但有一系列4篇文章介绍了如何使用Lync powershell cmdlet和C#。例如,下面是其中一篇文章的链接:

全套四篇文章发表在这里: