Hi,
I need to invoke powershell script of lync via the following c# code, however, there is a error:
"CommandNotFoundException was unhandled".
pls help me. thank you.
BTW, when I invoke powershell without lync module, it's ok.
Runspace runSpace = RunspaceFactory.CreateRunspace(); runSpace.Open(); Pipeline pipeLine = runSpace.CreatePipeline(); //string script = "Get-Process"; string script = "Get-CsSite"; pipeLine.Commands.AddScript(script); pipeLine.Commands.AddScript(@"Import-Module 'C:\Program Files\Common Files\Microsoft Lync Server 2010\Modules\Lync\Lync.psd1'"); pipeLine.Commands.Add("Out-String"); Collection<PSObject> results = pipeLine.Invoke(); StringBuilder stringBuilder = new StringBuilder(); foreach (PSObject obj in results) { stringBuilder.AppendLine(obj.ToString()); } Console.WriteLine(stringBuilder.ToString()); runSpace.Close(); Console.ReadLine();