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 ???