none
Using powershell cmdlet with Lync

    Question

  • Hi Team,

    I am trying to run a few commands like Get-CsServerVersion and Test-CsDatabase -LocalService using the following code :

    Runspace runSpace = RunspaceFactory.CreateRunspace();
                runSpace.Open();
    
                Pipeline pipeLine = runSpace.CreatePipeline();
    
                //string script = Get-Process;
                string script = "Get-CsServerVersion";
                pipeLine.Commands.AddScript(@"Import-Module 'C:\Program Files\Common Files\\Microsoft Lync Server 2013\Modules\Lync\Lync.psd1'");
                pipeLine.Commands.AddScript(script);
    
    
                pipeLine.Commands.Add("Out-String");
    
                Collection<PSObject> results = pipeLine.Invoke();
    
                StringBuilder stringBuilder = new StringBuilder();
                foreach (PSObject obj in results)
                {
                    stringBuilder.AppendLine(obj.ToString());
                }


    But the error i get is :

    "The term 'Get-CsServerVersion' 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."

     Can you please help me resolve this .

    Thanks and Regards.

    jeudi 10 mars 2016 05:51

Toutes les réponses

  • Hello,

    Have you tried importing the module first? Like import-module <module name>

    Best regards

    Rickard

    jeudi 10 mars 2016 07:56
  • Hi Richard,

    Thanks for your reply. Yes, i have imported it first and then added the script.

     string script = "Get-CsServerVersion";
                pipeLine.Commands.AddScript(@"Import-Module 'C:\Program Files\Common Files\\Microsoft Lync Server 2013\Modules\Lync\Lync.psd1'");
                pipeLine.Commands.AddScript(script);
    

    Also, i want to get the names of the Lync SQL instance and the instances of each database , for which i am trying to use "est-CsDatabase -LocalService" . Can you please help on how to use this cmdlet.


    Thanks


    • Modifié VKG123 jeudi 10 mars 2016 11:41
    jeudi 10 mars 2016 09:00
  • Hello,

    Sorry to inform you that, this cmdlet does not support pipelined input!

    Proof: https://technet.microsoft.com/en-us/library/gg398470.aspx 


    Best Regards Lingaraj Benni Please comment or like, if the above fix resolves your issue.

    jeudi 10 mars 2016 14:26
  • Hi Lingaraj,

    So how do we get the Lync Server version. Also, how to use "Test-CsDatabase -LocalService" to get the names of the Lync SQL instance and the instances of each database, using powershell in C# code. ??.

    Thanks.

    vendredi 11 mars 2016 04:11