Quantcast
Channel: Microsoft Unified Communications Managed API SDK forum
Viewing all articles
Browse latest Browse all 889

Help: Powershell of Lync invoked by C# is error

$
0
0

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();


Viewing all articles
Browse latest Browse all 889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>