Created
November 19, 2015 16:24
-
-
Save tohuw/c37e85f464cda8b6db56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.