none
Creating a mailbox enabled user via C# & PowerShell Remoting in Exchange 2007 RRS feed

  • Question

  • ok. so far every code snipplet on how to create an mailbox enabled user remotely using C# works for Exchange 2010 only.

    as far as i can see Exchange 2007 supports PowerShell 2.0, which in turn supports remoting, but for whatever reason i simply can't get it to work. Also, there seem no be no samples on the web addressing this issue.

    i unsuccessfully tried to adapt an Exchange 2010 sample:

     

    	  string pwd = "blablabla";
          SecureString securePwd = new SecureString();
          foreach (char ch in pwd)
          {
            securePwd.AppendChar(ch);
          }
    
          PSCredential credential = new PSCredential("Administrator@domain.local", securePwd);
          WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("http://exchangebox:5985/wsman"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);
          connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
    
          Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo);
    
          PowerShell powershell = PowerShell.Create();
          PSCommand command = new PSCommand();
          command.AddCommand("Get-Mailbox");
          command.AddParameter("Identity", "dummyuser");
          powershell.Commands = command;
          try
          {
            // open the remote runspace
            runspace.Open();
            // associate the runspace with powershell
            powershell.Runspace = runspace;
            // invoke the powershell to obtain the results
            Collection<PSObject> collection = new Collection<PSObject>();
            collection = powershell.Invoke();
          }
          finally
          {
            // dispose the runspace and enable garbage collection
            runspace.Dispose();
            runspace = null;
            // Finally dispose the powershell and set all variables to null to free
            // up any resources.
            powershell.Dispose();
            powershell = null;
          }
    

    which throws an exception at runspace.Open();

     

    System.Management.Automation.Remoting.PSRemotingTransportException was unhandled
      Message=Connecting to remote server failed with the following error message : The WS-Management service cannot process the request. The resource URI (http://schemas.microsoft.com/powershell/Microsoft.Exchange) was not found in the WS-Management catalog. The catalog contains the metadata that describes resources, or logical endpoints. For more information, see the about_Remote_Troubleshooting Help topic.
      Source=System.Management.Automation
      WasThrownFromThrowStatement=false
      ErrorCode=-2144108485
      TransportMessage=The WS-Management service cannot process the request. The resource URI is missing or it has an incorrect format. Check the documentation or use the following command for information on how to construct a resource URI: "winrm help uris".

     

    so ... any ideas on how to batch-create mailboxes remotely using c# and Exchange 2007? i know i could run a WCF service on my exchange box and do all that stuff locally, but there has to be some other way.

     

    thanks,

    Tom

    • Moved by Gen LinModerator Friday, July 23, 2010 3:42 AM a development problem (From:General Discussions)
    Wednesday, July 21, 2010 10:54 AM

All replies

  • You should post this in the Development forum.
    --
    Ed Crowley MVP
    "There are seldom good technological solutions to behavioral problems."
    .
    "TomTom1234" wrote in message news:7bad39d8-3190-4b9f-bb65-14dc7de8ea2a...

    ok. so far every code snipplet on how to create an mailbox enabled user remotely using C# works for Exchange 2010 only.

    as far as i can see Exchange 2007 supports PowerShell 2.0, which in turn supports remoting, but for whatever reason i simply can't get it to work. Also, there seem no be no samples on the web addressing this issue.

    i unsuccessfully tried to adapt an Exchange 2010 sample:

     

    	 string pwd = "blablabla";
       SecureString securePwd = new SecureString();
       foreach (char ch in pwd)
       {
        securePwd.AppendChar(ch);
       }
    
       PSCredential credential = new PSCredential("Administrator@domain.local", securePwd);
       WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("http://exchangebox:5985/wsman"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);
       connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
    
       Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo);
    
       PowerShell powershell = PowerShell.Create();
       PSCommand command = new PSCommand();
       command.AddCommand("Get-Mailbox");
       command.AddParameter("Identity", "dummyuser");
       powershell.Commands = command;
       try
       {
        // open the remote runspace
        runspace.Open();
        // associate the runspace with powershell
        powershell.Runspace = runspace;
        // invoke the powershell to obtain the results
        Collection<PSObject> collection = new Collection<PSObject>();
        collection = powershell.Invoke();
       }
       finally
       {
        // dispose the runspace and enable garbage collection
        runspace.Dispose();
        runspace = null;
        // Finally dispose the powershell and set all variables to null to free
        // up any resources.
        powershell.Dispose();
        powershell = null;
       }
    

    which throws an exception at runspace.Open();

     

    System.Management.Automation.Remoting.PSRemotingTransportException was unhandled
      Message=Connecting to remote server failed with the following error message : The WS-Management service cannot process the request. The resource URI (http://schemas.microsoft.com/powershell/Microsoft.Exchange) was not found in the WS-Management catalog. The catalog contains the metadata that describes resources, or logical endpoints. For more information, see the about_Remote_Troubleshooting Help topic.
      Source=System.Management.Automation
      WasThrownFromThrowStatement=false
      ErrorCode=-2144108485
      TransportMessage=The WS-Management service cannot process the request. The resource URI is missing or it has an incorrect format. Check the documentation or use the following command for information on how to construct a resource URI: "winrm help uris".

     

    so ... any ideas on how to batch-create mailboxes remotely using c# and Exchange 2007? i know i could run a WCF service on my exchange box and do all that stuff locally, but there has to be some other way.

     

    thanks,

    Tom


    Ed Crowley MVP "There are seldom good technological solutions to behavioral problems."
    Wednesday, July 21, 2010 4:34 PM