none
EWS get equipment RRS feed

  • Question

  • EWS for 2010 defines getRoomLists/getRooms - is there any way to get the list of equipment - or maybe just a list of all resources - i.e. all rooms and all equipment.

    Thanks 

    Wednesday, September 28, 2011 10:05 PM

Answers

  • Two methods you could use first if you want to use EWS you can create a Dynamic distribution Group using New-DynamicDistributionGroup http://technet.microsoft.com/en-us/library/bb125127.aspx using the IncludedRecipients parameter to restrict the group to resources. Then in EWS use ExpandDL http://msdn.microsoft.com/en-us/library/aa494152(v=exchg.140).aspx.

    You can also use Remote powershell instead and then just use Get-Mailbox -equipment  the advantage of using Remote Powershell is that you will also be able to also get all the Custom resource properties on the mailboxes. You can also just use LDAP via System.DirectoryServices which is generally the best method to use for any OnPrem directory access (but doesn't work for instance for Exchange Online etc).

    Cheers
    Glen 

    Thursday, September 29, 2011 4:33 AM

All replies

  • Two methods you could use first if you want to use EWS you can create a Dynamic distribution Group using New-DynamicDistributionGroup http://technet.microsoft.com/en-us/library/bb125127.aspx using the IncludedRecipients parameter to restrict the group to resources. Then in EWS use ExpandDL http://msdn.microsoft.com/en-us/library/aa494152(v=exchg.140).aspx.

    You can also use Remote powershell instead and then just use Get-Mailbox -equipment  the advantage of using Remote Powershell is that you will also be able to also get all the Custom resource properties on the mailboxes. You can also just use LDAP via System.DirectoryServices which is generally the best method to use for any OnPrem directory access (but doesn't work for instance for Exchange Online etc).

    Cheers
    Glen 

    Thursday, September 29, 2011 4:33 AM
  • Thanks a lot Glen - it reall yclarified it a bit. One additional question, though: If I get you right: If I create an equipment mail box via power shell or the console - does it get created in AD behind the scenes?

    Here's what I'm at right now:

    My approach is to call PowerShell from C# - this can be set up with a reference to:

    C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll

    Then in C# some imports:

    using System.Management.Automation;
    
    
    
    using System.Management.Automation.Runspaces;
    
    
    
    using System.Collections.ObjectModel;
    
    
    
    


    And finally:

     RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    PSSnapInException snapInException = null;
    PSSnapInInfo info = rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", out snapInException);
    Runspace myRunSpace = RunspaceFactory.CreateRunspace(rsConfig);
    myRunSpace.Open();
    Pipeline pipeline = myRunSpace.CreatePipeline();
    Command cmd = new Command("Get-Mailbox");
    cmd.Parameters.Add("RecipientTypeDetails", "EquipmentMailbox");               
    pipeline.Commands.Add(cmd);                
    Collection<PSObject> results = new Collection<PSObject>();
    results = pipeline.Invoke();
    myRunSpace.Close();

    For some reason I had to target x64 (not x86) in my build settings. Otherwise I got an error saying something like 'no cmdlets registered for powershell 2'.

    BR Jesper, Software developer




    Thursday, September 29, 2011 8:17 AM
  • >>If I get you right: If I create an equipment mail box via power shell or the console - does it get created in AD behind the scenes?

    Yes like mailboxes equipment/room mailboxes have a associated Active Directory account the only thing that's a little special is that this account is disabled by default (eg to prevent the user account being used)

    What you doing isn't remote powershell you just loading the snapin into the local powershell session which will work but it will only work directly on a Exchange server. If you want to run the code remotely then use Remote Powershell eg have a look at http://blogs.msdn.com/b/mvpawardprogram/archive/2011/08/29/mvps-for-exchange-online-calling-exchange-online-powershell-cmdlets-from-c.aspx The only thing to change between Cloud and OnPrem in the URL and possibly the auth to NTLM eg for a vanilla Exchange 2010 you should use something like

     

                    String AdminUserName = unUserName;
                    String Password = pnPassword;
    
                    System.Security.SecureString secureString = new System.Security.SecureString();
                    foreach (char c in Password)
                        secureString.AppendChar(c);
                    PSCredential credential = new PSCredential(AdminUserName, secureString);
                    WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("https://" + snServerName + "/PowerShell"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);
                    connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
                    connectionInfo.SkipCACheck = true;
                    connectionInfo.SkipCNCheck = true;
    
                    connectionInfo.MaximumConnectionRedirectionCount = 4;
                    Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(connectionInfo);
                    try
                    {
                        runspace.Open();
                    }
                    catch (Exception exception)
                    {
                        if (exception is System.Management.Automation.Remoting.PSRemotingTransportException)
                        {
                            switch (((System.Management.Automation.Remoting.PSRemotingTransportException)exception).ErrorCode)
                            {
                                case 5: throw new Exception("Auth error check UserName and Password");
                                    break;
                                case -2144108526: throw new Exception("Issue with Remote Powershell URL");
                                    break;
                                default: throw new Exception(exception.Message);
                                    break;
                            }
                        }
                    }
                    // Make a Get-Mailbox Request
                    Command grGetRecipient = new Command("Get-Mailbox");
                    grGetRecipient.Parameters.Add("ResultSize", "Unlimited");
                    Pipeline plPileLine = runspace.CreatePipeline();
                    plPileLine.Commands.Add(grGetRecipient);
                    Collection<PSObject> RsResultsresults = plPileLine.Invoke();
                    foreach (PSObject obj in RsResultsresults)
                    {
    			Console.WriteLine(obj.Properties["DisplayName"].Value.ToString())
    
                    }
                    plPileLine.Stop();
                    plPileLine.Dispose();
    

     


    Thursday, September 29, 2011 9:23 AM
  • Hi, Glen thanks for the remote example. We tried the remote solution but keep getting an "Access is Denied" back:

    "Processing data from remote server failed with the following error message: Access is denied. For more information, see the about_Remote_Troubleshooting Help topic"

    We tried using basic and negotiate etc. in combination with <username> and  <domain>\<username> as first argument in PSCredential but no difference.

    Regards

    Thursday, November 17, 2011 4:45 PM
  • If I run the very same code from within a console application with an admin user, I don't get access problems so I suppose it has to do with the account used for executing Sharepoint 2010 custom WCF services.
    Saturday, November 19, 2011 1:09 PM