We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

Properties of room mailboxes

February 22, 2021 Views: 3737

The script generates and sends a report on properties of room mailboxes located in a specific AD domain.

Note: The script will export only properties of mailboxes hosted in Exchange 2007. To be able to run the script, you need to install Microsoft Exchange Server 2007 Management Tools on the computer where Adaxes service is installed.

To schedule the report, create a scheduled task configured for the Domain-DNS object type that runs the script and assign it over the domain where the room mailboxes are located. To add the script to a scheduled task, use the Run a program or PowerShell script action.

Parameters:

  • $to - Specifies a comma separated list of recipients of the report.
  • $subject - Specifies the email message subject.
  • $reportHeader - Specifies the email message header.
  • $tableHeader - Specifies the header for a table containing properties of the mailboxes.
  • $reportFooter - Specifies the email message footer.
  • $calendarProperties - Specifies the properties of the mailbox calendar to include in the report.
Edit Remove
PowerShell
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin

$to = "recipient@domain.com" # TODO: modify me
$subject = "Room Mailboxes Report" # TODO: modify me
$reportHeader = "<h2><b>Room Mailboxes Report</b></h2><br/>" # TODO: modify me
$tableHeader = @"
<table border="1">
    <tr>
        <th>Name</th>
        <th>Display Name</th>
        <th>Alias</th>
        <th>Recipient type details</th>
        <th>User Principle Name</th>
        <th>Primary SMTP</th>
        <th>Resource Custom</th>
        <th>Notes</th>
        <th>Title</th>
        <th>CustomAttributes</th>
        <th>PublicDelegate Value (AD Attribute)</th>
        <th>Calendar settings</th>
    </tr>
"@ # TODO: modify me
$reportFooter = "<hr /><p><i>Please do not reply to this e-mail, it has been sent to you for notification purposes only.</i></p>" # TODO: modify me

$calendarProperties = @(
    "AutomateProcessing",
    "AllowConflicts",
    "BookingWindowInDays",
    "MaximumDurationInMinutes",
    "AllowRecurringMeetings",
    "EnforceSchedulingHorizon",
    "ScheduleOnlyDuringWorkHours",
    "ConflictPercentageAllowed",
    "MaximumConflictInstances",
    "ForwardRequestsToDelegates",
    "DeleteAttachments",
    "DeleteComments",
    "RemovePrivateProperty",
    "DeleteSubject",
    "DisableReminders",
    "AddOrganizerToSubject",
    "DeleteNonCalendarItems",
    "TentativePendingApproval",
    "EnableResponseDetails",
    "OrganizerInfo",
    "ResourceDelegates",
    "RequestOutOfPolicy",
    "AllRequestOutOfPolicy",
    "BookInPolicy",
    "AllBookInPolicy",
    "RequestInPolicy",
    "AllRequestInPolicy",
    "AddAdditionalResponse",
    "AdditionalResponse",
    "RemoveOldMeetingMessages",
    "AddNewRequestsTentatively",
    "ProcessExternalMeetingMessages",
    "DefaultReminderTime",
    "RemoveForwardedMeetingNotifications") # TODO: modify me

function GetPropertyValues ($guid, $properties)
{
    $domain = $Context.GetObjectDomain("%distinguishedName%")
    $searcher = $Context.BindToObject("Adaxes://$domain/rootDSE")
    $searcher.SearchFilter = [Softerra.Adaxes.Ldap.FilterBuilder]::Create("ObjectGuid", [Guid]$guid)
    $searcher.SizeLimit = 1
    $searcher.SetPropertiesToLoad($properties)
    
    try
    {
        $searchResultIterator = $searcher.ExecuteSearch()
        $result = $searchResultIterator.FetchAll()
        
        if ($result.Length -eq 0)
        {
            $Context.LogMessage("No room mailboxes found in domain '$domain'", "Warning")
            return $NULL
        }
        else
        {
            $propertiesFromAd = New-Object PSObject
            foreach ($property in $properties)
            {
                $propertyValues = $result[0].Properties[$property].Values
                if ($propertyValues.Count -gt 1)
                {
                    $listValues = "<ul>"
                    foreach ($value in $propertyValues)
                    {
                        $listValues += "<li>$value</li>"
                    }
                    $listValues += "</ul>"
                    $propertiesFromAd | Add-Member -Name $property -MemberType NoteProperty -value $listValues
                }
                else
                {
                    $propertiesFromAd | Add-Member -Name $property -MemberType NoteProperty -value $propertyValues
                }
                
            }
            return $NULL
        }
        
    }
    finally
    {
        $searchResultIterator.Dispose()
    }
}

# Get all room mailboxes
[System.Array]$mailboxes = Get-Mailbox -RecipientTypeDetails Roommailbox -ResultSize "unlimited"

# Build report
foreach ($mailbox in $mailboxes)
{
    # Get properties from AD
    $mailboxGuid = $mailbox.Guid.ToString()
    $propertiesFromAd = GetPropertyValues $mailboxGuid @("info", "title", "publicDelegates")
    
    # Get Custom Attributes
    $customAttributeList = "<ul>"
    for ($i = 1; $i -le 15; $i++)
    {
        $customAttributeList += "<li>CustomAttribute$i`: " + $mailbox."CustomAttribute$i" + "</li>"
    }
    $customAttributeList += "</ul>"
    
    # Add properties specific to Room Mailboxes
    $resourceCustom = $mailbox.ResourceCustom -join ";"
    $tableHeader += "<tr valign='top' style='white-space: nowrap'>
        <td>$($mailbox.Name)</td>
        <td>$($mailbox.DisplayName)</td>
        <td>$($mailbox.Alias)</td>
        <td>$($mailbox.RecipientTypeDetails)</td>
        <td>$($mailbox.UserPrincipalName)</td>
        <td>$($mailbox.PrimarySmtpAddress)</td>
        <td>$resourceCustom</td>
        <td>$($propertiesFromAd.info)</td>
        <td>$($propertiesFromAd.title)</td>
        <td>$customAttributeList</td>
        <td>$($propertiesFromAd.publicDelegates)</td>"
    
    # Add Calendar Settings to the report
    $calenarSettings = $mailbox | Get-MailboxCalendarSettings 
    $calenarSettingsList = "<ul>"
    foreach ($property in $calendarProperties)
    {
        $propertyValue = $calenarSettings.$property
        if ($property -eq "ResourceDelegates")
        {
            $listValues = "<ul>"
            foreach ($value in $propertyValue)
            {
                $listValues += "<li>$value</li>"
            }
            $listValues += "</ul>"
            $calenarSettingsList += "<li>$property`:$listValues</li>"
        }
        else
        {
            $calenarSettingsList += "<li>$property`:$propertyValue</li>"
        }
    }
    $calenarSettingsList += "</ul>"
    $tableHeader += "<td>$calenarSettingsList</td></tr>"
}
$tableHeader += "</table>"
$tableHeader += "<br/><b>RoomMailbox Count</b>:" + $mailboxes.Length

# Send report
$html = $reportHeader + $tableHeader + $reportFooter
$Context.SendMail($to, $subject, $NULL, $html)
Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers