I am trying to get the mailbox using powershell cmdlet in c# program. I can see connection is being initialized successfully but when try to execute the get-mailbox cmdlet, i see the following error.
The term 'Get-Mailbox' 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.Runspaces.PipelineBase.Invoke(IEnumerable input)
at System.Management.Automation.Runspaces.Pipeline.Invoke()
below is my c# code
Command cmd= new Command("Get-Mailbox");
cmd.Parameters.Add("Identity", "xxxxxx");
Collection<PSObject> results = new Collection<PSObject>();
runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipe = runspace.CreatePipeline();
pipe.Commands.Add(Cmd);
results = pipe.Invoke();