Although the previous version of this function that I posted earlier worked, all of the “-like” operators should have been replaced with the “-eq” operator. Looks like I forgot to finish changing them after copying and pasting from your script. There’s no reason to use the like operator unless you using doing some sort of wildcard matching (-like allows the use of *). Here’s an updated version of the function that’s been corrected:
Add-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010
function Get-EmailFolderPermission {
[CmdletBinding()]
param (
[string]$OrganizationalUnit = 'domain/EDD/Resources',
[string]$MailboxType = 'SharedMailbox'
)
$Mailboxes = Get-Mailbox -RecipientTypeDetails $MailboxType -OrganizationalUnit $OrganizationalUnit
foreach ($Mailbox in $Mailboxes){
$Folders = Get-MailboxFolderStatistics -Identity $mailbox |
Where-Object {$_.foldertype -eq 'Calendar' -or
$_.foldertype -eq 'Contacts' -or
$_.foldertype -eq 'User Created' -or
$_.foldertype -eq 'DeletedItems' -or
$_.foldertype -eq 'SentItems' -or
$_.foldertype -eq 'Inbox' -or
$_.foldertype -eq 'Tasks'}
foreach ($Folder in $Folders) {
$FolderName = "$($Mailbox):$($Folder.FolderID)"
$Permissions = Get-MailboxFolderPermission -Identity $FolderName
foreach ($Permission in $Permissions){
$Results = @{
Mailbox = "$($Mailbox.DisplayName)$($Folder.FolderPath)"
User = $Permission.User
AccessRights = $Permission.AccessRights
}
New-Object PSObject -Property $Results
}
}
}
}
µ