Monday, December 14, 2015

Showing the Calendar Configuration of a Mailbox or Meeting Room using EWS

When you configure Calendar processing settings in Exchange either using the Exchange Administrator Centre via the Exchange Management Shell (Set-CalendarProcessing) many of these setting get held in a FAI (Folder Associated Item) in the Calendar Folder of the Mailbox in question. In EWS you can access these configuration objects using the UserConfiguration operation and classes.

The Calendar settings are stored in the Roaming Dictionary format to store each of the different Key and Value pairs. For some of the settings like the bookin policy (In-policy meeting requests) and (Out-of-policy meeting requests) these are stored as an array of ExchangeDn's.

I've put together a script cmdlet called Show-CalendarSettings that can dump out the Roaming dictionary setting for a Calendar Configuration object using EWS. And also for the BookIn and RequestIn policy it will loop through each of the ExchangeDn's in the array and try to resolve each of the entries via ResolveName . All the configuration information is written to file and the results of the ResolveName is written along with the result (eg valid if it resolves couldn't resolve if not). eg it produces an output like




  I've put the script on GitHub here https://github.com/gscales/Powershell-Scripts/blob/master/DumpCalSettings.ps1 and the script itself look like

function Show-CalendarSettings
{
    param( 
     [Parameter(Position=0, Mandatory=$true)] [string]$MailboxName,
  [Parameter(Position=1, Mandatory=$true)] [System.Management.Automation.PSCredential]$Credentials,
  [Parameter(Position=2, Mandatory=$false)] [switch]$useImpersonation,
  [Parameter(Position=3, Mandatory=$false)] [string]$url
    )  
  Begin
 {
  $service = Connect-Exchange -MailboxName $MailboxName -Credentials $Credentials
  if($useImpersonation.IsPresent){
   $service.ImpersonatedUserId = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)
  }
  # Bind to the Calendar Folder
  $folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar,$MailboxName)   
  $Calendar = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
  $UsrConfig = [Microsoft.Exchange.WebServices.Data.UserConfiguration]::Bind($service, "Calendar", $Calendar.Id, [Microsoft.Exchange.WebServices.Data.UserConfigurationProperties]::All)  
  #$UsrConfig.Dictionary
  $rptCollection = @()
  foreach($cnfObj in $UsrConfig.Dictionary.Key){
   $rptObj = "" | Select Property,Value,Valid
   $rptObj.Property = $cnfObj
   $rptObj.Valid = "Ok"
   $rptObj.Value = $UsrConfig.Dictionary[$cnfObj]
   $rptCollection +=$rptObj
   if($cnfObj -eq "BookInPolicyLegDN")
   {
    foreach($LegDn in $UsrConfig.Dictionary["BookInPolicyLegDN"])
    {
        $ncCol = $service.ResolveName($LegDn, [Microsoft.Exchange.WebServices.Data.ResolveNameSearchLocation]::DirectoryOnly, $false);
           if($ncCol.Count -gt 0){
      #Write-output ("Found " + $ncCol[0].Mailbox.Address)
      $rptObj = "" | Select Property,Value,Valid
      $rptObj.Property = "BookInPolicyValue"
      $rptObj.Value = $ncCol[0].Mailbox.Address
      $rptObj.Valid = "Ok"
      $rptCollection +=$rptObj
           }
     else
     { 
      #Write-Output "Couldn't resolve " + $LegDn
      $rptObj = "" | Select Property,Value,Valid
      $rptObj.Property = "BookInPolicyValue"
      $rptObj.Value = $LegDn
      $rptObj.Valid = "Couldn't resolve"
      $rptCollection +=$rptObj
     }
     
    } 
   }
   if($cnfObj -eq "RequestInPolicyLegDN")
   {
    foreach($LegDn in $UsrConfig.Dictionary["RequestInPolicyLegDN"])
    {
        $ncCol = $service.ResolveName($LegDn, [Microsoft.Exchange.WebServices.Data.ResolveNameSearchLocation]::DirectoryOnly, $false);
           if($ncCol.Count -gt 0){
      #Write-output ("Found " + $ncCol[0].Mailbox.Address)
      $rptObj = "" | Select Property,Value,Valid
      $rptObj.Property = "RequestInPolicyValue"
      $rptObj.Value = $ncCol[0].Mailbox.Address
      $rptObj.Valid = "Ok"
      $rptCollection +=$rptObj
           }
     else
     { 
      #Write-Output "Couldn't resolve " + $LegDn
      $rptObj = "" | Select Property,Value,Valid
      $rptObj.Property = "RequestInPolicyValue"
      $rptObj.Value = $LegDn
      $rptObj.Valid = "Couldn't resolve"
      $rptCollection +=$rptObj
     }
     
    }   
   }
  }
  Write-Output $rptCollection
   
  $rptCollection | Export-Csv -Path ("$MailboxName-CalendarSetting.csv") -NoTypeInformation
 }
}

1 comment:

puffyismydog said...

Hi, I've performed a GetUserConfiguration request and received the following 3 values for BookInPolicy, but I don't know how to use/query them.



String
BookInPolicy


StringArray
75480a35-de48-46ad-8378-7c66137de736
498e21e9-1d88-4254-bea0-8d976c3e451d
08ffb1dd-64b8-438f-a924-ac3782975abf