locked
EWS Powershell - Delegate reports RRS feed

  • Question

  • OK, I am having problems getting ther below script to run. It has been put together from Glens Exchange Dev blog but not sure if I am missing something. Is there an expert here willing to take a look and help a powershell noob!??

    The script fails on line 75 (Which i have highlighted in black)

    Thanks in advance!

    Ant

    ## EWS Managed API Connect Module Script written by Glen Scales
    ## Requires the EWS Managed API and Powershell V2.0 or greator

    ## Load Managed API dll
    Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\1.2\Microsoft.Exchange.WebServices.dll"

    ## Set Exchange Version
    $ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP2

    ## Create Exchange Service Object
    $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($ExchangeVersion)

    ## Set Credentials to use two options are availible Option1 to use explict credentials or Option 2 use the Default (logged On) credentials

    #Credentials Option 1 using UPN for the windows Account
    $creds = New-Object System.Net.NetworkCredential("name@domain.com","PASSWORD")
    $service.Credentials = $creds   

    #Credentials Option 2
    #service.UseDefaultCredentials = $true

    ## Choose to ignore any SSL Warning issues caused by Self Signed Certificates

    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

    ## Set the URL of the CAS (Client Access Server) to use two options are availbe to use Autodiscover to find the CAS URL or Hardcode the CAS to use

    #CAS URL Option 1 Autodiscover
    #$service.AutodiscoverUrl("name@domain.com",{$true})
    #"Using CAS Server : " + $Service.url
     
    #CAS URL Option 2 Hardcoded

    $uri=[system.URI] "https://CASSERVER.FQDN/ews/exchange.asmx"
    $service.Url = $uri 

    ## Optional section for Exchange Impersonation

    #$service.ImpersonatedUserId = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, "email@domain.com")

    ##Generate delegate report##

    $rptCollection = @() 
    #Get Delegates for Mailbox 
    $delegates = $service.getdelegates($MailboxName,$true)
    #Enumerate Delegates 
    foreach($Delegate in $delegates.DelegateUserResponses){ 
        $rptObj = "" | select EmailAddress,Inbox,Calendar,Contacts,Tasks,Notes,Journal,MeetingMessages,ViewPrivateItems 
        $rptObj.EmailAddress = $Delegate.DelegateUser.UserId.PrimarySmtpAddress 
        $rptObj.Inbox = $Delegate.DelegateUser.Permissions.InboxFolderPermissionLevel 
        $rptObj.Calendar = $Delegate.DelegateUser.Permissions.CalendarFolderPermissionLevel 
        $rptObj.Contacts = $Delegate.DelegateUser.Permissions.ContactsFolderPermissionLevel 
        $rptObj.Tasks = $Delegate.DelegateUser.Permissions.TasksFolderPermissionLevel 
        $rptObj.Notes = $Delegate.DelegateUser.Permissions.NotesFolderPermissionLevel 
        $rptObj.Journal = $Delegate.DelegateUser.Permissions.JournalFolderPermissionLevel 
        $rptObj.ViewPrivateItems = $Delegate.DelegateUser.ViewPrivateItems 
        $rptObj.MeetingMessages = $Delegate.DelegateUser.ReceiveCopiesOfMeetingMessages 
        $rptCollection += $rptObj 

     
    $tableStyle = @"
    <style>
    BODY{background-color:white;}
    TABLE{border-width: 1px;
      border-style: solid;
      border-color: black;
      border-collapse: collapse;
    }
    TH{border-width: 1px;
      padding: 10px;
      border-style: solid;
      border-color: black;
      background-color:#66CCCC
    }
    TD{border-width: 1px;
      padding: 2px;
      border-style: solid;
      border-color: black;
      background-color:white
    }
    </style>
    "@ 
       
    $body = @"
    <p style="font-size:25px;family:calibri;color:#ff9100"> 
    $TableHeader 
    </p> 
    "@ 
     
    $rptCollection | ConvertTo-HTML -head $tableStyle | Out-File c:\delgateReport.html

    Tuesday, December 4, 2012 3:37 PM

Answers

  • Hi,NovAnt,

    I cannot see the highlighted in black for the error happening in your initial post.I am not familar with powershell but you can run $error[0] | fl -force  after you run the script to get more information on the error.If you then see something like "There is no Runspace available to run scripts in this thread" in the detail of the error you might want to have a look at this thread http://social.technet.microsoft.com/Forums/en-AU/exchangesvrdevelopmentlegacy/thread/ad493b72-6465-450b-bd49-8f15675d7f53 which is also answered by Glen.

    Again,I also recommend you to post the question on developmeng forum as Lee suggested,there would be more developping experts reside there will give you professional help.

    Regards,

    Sharon


    Sharon Shen
    TechNet Community Support

    ************************************************************************************************************************

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.

    • Proposed as answer by Sharon.Shen Monday, December 17, 2012 2:56 AM
    • Marked as answer by Sharon.Shen Friday, December 28, 2012 7:58 AM
    Wednesday, December 5, 2012 9:16 AM

All replies

  • I can't see where a value gets assigned to the variable $MailboxName.  Can you give a link to the original article?

    Mobile OWA For Smartphone
    www.leederbyshire.com
    email a@t leederbyshire d.0.t c.0.m

    Tuesday, December 4, 2012 4:23 PM
  • Hi Lee, thanks for the response.

    I have provided a link to the original article below. I did try inserting a $MailboxName = "test" further up in the script but it didn’t work either. I get error:

    Exception calling "GetDelegates" with "3" argument(s): "The request failed. The underlying connection was closed: An unexpected error occurred on a send.

    Article

    http://gsexdev.blogspot.co.uk/2012/03/ews-managed-api-and-powershell-how-to.html#!/2012/03/ews-managed-api-and-powershell-how-to.html

    Tuesday, December 4, 2012 4:42 PM
  • I assume you have supplied your own server names and account names and email addresses in all the relevant places in the code?  Might also be worth looking at the iis log file at the server end, to see how it responded.

    BTW, you'd have more luck with the question if you placed it in the development forum:

    http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopmentlegacy/threads

    Glen himself hangs out there, and is sure to help.


    Mobile OWA For Smartphone
    www.leederbyshire.com
    email a@t leederbyshire d.0.t c.0.m

    • Proposed as answer by Sharon.Shen Wednesday, December 5, 2012 9:02 AM
    Tuesday, December 4, 2012 5:04 PM
  • I have supplied all the names, addresses etc, I just removed them before posting.

    I will check the log as suggested and have also re-posted in the Dev forum.

    Thanks for taking the time to look at this!

    Ant

    Wednesday, December 5, 2012 9:16 AM
  • Hi,NovAnt,

    I cannot see the highlighted in black for the error happening in your initial post.I am not familar with powershell but you can run $error[0] | fl -force  after you run the script to get more information on the error.If you then see something like "There is no Runspace available to run scripts in this thread" in the detail of the error you might want to have a look at this thread http://social.technet.microsoft.com/Forums/en-AU/exchangesvrdevelopmentlegacy/thread/ad493b72-6465-450b-bd49-8f15675d7f53 which is also answered by Glen.

    Again,I also recommend you to post the question on developmeng forum as Lee suggested,there would be more developping experts reside there will give you professional help.

    Regards,

    Sharon


    Sharon Shen
    TechNet Community Support

    ************************************************************************************************************************

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.

    • Proposed as answer by Sharon.Shen Monday, December 17, 2012 2:56 AM
    • Marked as answer by Sharon.Shen Friday, December 28, 2012 7:58 AM
    Wednesday, December 5, 2012 9:16 AM
  • I assumed you had, it's just that an incorrect server name (or even having it resolve to something like your router's built-in admin web site), or incorrect credentials seem to me to be most likely to cause the connection to be closed.  My thought was that maybe you'd missed one variable, rather than that you'd not changed any at all.

    Mobile OWA For Smartphone
    www.leederbyshire.com
    email a@t leederbyshire d.0.t c.0.m

    Wednesday, December 5, 2012 1:15 PM
  • Did you make two posts about the same thing or is this another problem?

    EWS Delegate report script

    <p style="font-size:25px;family:calibri;color:#ff9100">

    Try changing it to:

    <p style='font-size:25px;family:calibri;color:#ff9100'> 

    stefan@xperta


    • Edited by stefan-iz Wednesday, December 5, 2012 1:30 PM ...
    Wednesday, December 5, 2012 1:24 PM
  • Hi,NovAnt,

    Any updates here?

    Regards,

    Sharon


    Sharon Shen
    TechNet Community Support

    ************************************************************************************************************************

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.

    Monday, December 17, 2012 2:52 AM