0

I am getting below exception if run lync powershell command "Get-CsUser". I am running application with administrator and on machine which have lync powershell.

System.Management.Automation.CommandNotFoundException: The term 'Get-CsUser' 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. at System.Management.Automation.CommandDiscovery.LookupCommandInfo(String commandName, CommandOrigin commandOrigin) at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName, CommandOrigin commandOrigin, Nullable`1 useLocalScope)
at System.Management.Automation.Runspaces.Command.CreateCommandProcessor(ExecutionContext executionContext, CommandFactory commandFactory, Boolean addToHistory) at System.Management.Automation.Runspaces.LocalPipeline.CreatePipelineProcessor() at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper() at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()

sample code:

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

any suggestion to fix this ???

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user3180614
  • 1
  • 1
  • 1

1 Answers1

0

I don't have an answer, but there is a series of 4 articles that describe using Lync powershell cmdlets and C#. For example, here's a link to one of the articles:

PowerShell Scripting Lync 2010 SDK Using Lync Model API

The full set of four articles is published here:

Lync 2010 Technical Articles

user3076137
  • 111
  • 3