List mailboxes with delegates.
The script checks for the mailbox with delegates. If delegates are available , it gather delegate details and exports the details to CSV file.
PowerShell
write-host "The Script Started and gathering mailbox list" -foregroundcolor "Green"
$Combine=@();
$MBXList = get-mailbox -resultsize Unlimited | where {(!$_.name.startswith("SystemMailbox")) -and (!$_.name.startswith("FederatedEmail")) -and (!$_.name.startswith
("DiscoverySearchMailbox")) -and (!$_.name.startswith("Microsoft System"))}
$MBXList | foreach-object {
$curMBX=$_
$Alias = $curMBX.Alias
$DB = $curMBX.database
$SAName = $curMBX.samaccountname
$DName = $curMBX.DisplayName
$PEmail = $curMBX.PrimarySMTPAddress
write-progress -activity "Checking the MBX for delegates " -status "Currently processing the MBX(alias) : $Alias" -percentcomplete (($curgrpmplt/
$MBXList.count)*100)
$WithDel = Get-CalendarProcessing $Alias | where{$_.resourcedelegates -notlike ""}
if(($WithDel|measure).count -gt 0)
{
$DelDN = $WithDel.ResourceDelegates | ForEach { $_.DistinguishedName }
$DelDN | foreach-object {
$DelLst = New-Object Object
$curDel=$_
$DelMBX=Get-mailbox -identity $curDel
$DelName=$DelMBX.Name
$DelDName=$DelMBX.DisplayName
$DelPEmail=$DelMBX.PrimarySMTPAddress
add-member -input $DelLst -membertype noteproperty -name "OwnerName" -value $Alias -ea silentlycontinue
add-member -input $DelLst -membertype noteproperty -name "OwnerSamAccountName" -value $SAName -ea silentlycontinue
add-member -input $DelLst -membertype noteproperty -name "OwnerDisplayName" -value $DName -ea silentlycontinue
add-member -input $DelLst -membertype noteproperty -name "OwnerEmail" -value $PEmail -ea silentlycontinue
add-member -input $DelLst -membertype noteproperty -name "DelegateDisplayName" -value $DelDName -ea silentlycontinue
add-member -input $DelLst -membertype noteproperty -name "DelegateEmail" -value $DelPEmail -ea silentlycontinue
##$DelLst | select-object OwnerName,OwnerSamAccountName,OwnerDisplayName,OwnerEmail,DelDisplayName,DelEmail | Export-csv -path c:\test\test.txt -append
$combine+=$DelLst
}
}
$curgrpmplt++
}
$combine | Export-csv OwnerDelegateList.csv
write-host "The Script completed" -foregroundcolor "Green"
What the script does,
- Script collects the list of mailboxes.
- Checks for delegates for each mailbox.
- If the delegates present, then the details are exported to CSV file.
- Please make the changes in below location in the script to your need,
$combine | Export-csv OwnerDelegateList.csv
- The scripted tested with Exchange 2010 and Windows 2008 R2.
- You could download the script from https://gallery.technet.microsoft.com/office/List-mailboxes-with-6686d352