Skip to content

Instantly share code, notes, and snippets.

@tohuw
Created November 19, 2015 16:24
Show Gist options
  • Save tohuw/c37e85f464cda8b6db56 to your computer and use it in GitHub Desktop.
Save tohuw/c37e85f464cda8b6db56 to your computer and use it in GitHub Desktop.
[CmdletBinding (SupportsShouldProcess = $false)]
param (
$Mailboxes = @(),
[switch]$FormatTable = $true
)
begin {
$MailboxesLocationsPermissions = @()
$LocationsPermissions = @()
}
process {
foreach ($Mailbox in $Mailboxes) {
# Forward slashes are the path delimiter in the Get-MailboxFolderStatistics FolderPath property, but Get-MailboxFolderPermission uses backslashes for path delimiters.
# Forward slashes in any part of the path resolve to "" in the FolderPath property, so translate it back.
# "Top of Information Store" in the FolderPath property is simply "\" to Get-MailboxFolderPermission.
$Locations = $(Get-MailboxFolderStatistics -Identity $Mailbox).FolderPath.Replace("/","\").Replace("","/").Replace("Top of Information Store","")
foreach ($Location in $Locations) {
# Exclude permissions checks on the Dumpster non-IPM locations - they won't even resolve to their actual paths this way anyhow, and don't really support special ACLs.
if ($Location -ne "\Recoverable Items" -and $Location -ne "\Deletions" -and $Location -ne "\Purges" -and $Location -ne "\Versions") {
try {
$LocationsPermissions += Get-MailboxFolderPermission "$Mailbox`:$Location" -ErrorAction Stop
} catch {
if ($_.Exception.Message -like "*couldn't be found*") {
Write-Debug "Location `"$Mailbox`:$Location`" not found."
} elseif ($_.Exception.Message -like "*cannot call a method on a null-valued expression*") {
Write-Error "The value provided for Location was null or improperly formatted."
} else {
Write-Error $_
}
}
}
}
$MailboxesLocationsPermissions += $LocationsPermissions
}
}
end {
# The default output is nigh useless for quickly reading through, so include an option to pretty-format the data, though this does change the types...
if ($FormatTable) {
$MailboxesLocationsPermissions | Format-Table -Property User, AccessRights, IsValid -GroupBy FolderName -AutoSize
} else {
return $MailboxesLocationsPermissions
}
}
@tohuw
Copy link
Author

tohuw commented Nov 19, 2015

No Get-Help text yet, but it's fairly self-explanatory. Feed it one or more mailboxes, optionally specifying -FormatTable:$false to retain the native data types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment