none
Poweshell Command for Get-Mailbox RRS feed

  • Question

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

    Thursday, September 12, 2013 2:26 PM

All replies

  • Hi

    The account you executing this with, does it have the correct permissions in Exchange to be able to run it?

    Thursday, September 12, 2013 5:08 PM
    Moderator
  • Hi 

    You would need to load the poweshell exchange module before the 'get-mailbox' will work

    Wednesday, September 18, 2013 8:24 AM