Created
August 29, 2017 02:28
-
-
Save kevinblumenfeld/609fe3a56518d8d3b9a031eaac8d3a62 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -EA SilentlyContinue | |
Set-AdServerSettings -ViewEntireForest $true | |
$OutFile = ".\Exchange_Permission_Export.csv" | |
"DisplayName" + "!" + "Alias" + "!" + "OU" + "!" + "PrimarySMTP" + "!" + "FullAccess" + "!" + "SendAs" + "!" + "SendonBehalf" | Out-File $OutFile -Force -encoding ascii | |
# $Mailboxes = import-csv .\perms.csv | |
$Mailboxes = Get-Mailbox -ResultSize:Unlimited | Select DistinguishedName, UserPrincipalName, DisplayName, Alias, | |
@{n = "OU" ; e = {$_.Distinguishedname | ForEach-Object {($_ -split '(OU=)', 2)[1, 2] -join ''}}} | |
ForEach ($Mailbox in $Mailboxes) { | |
Write-Output "Mailbox: $($Mailbox.UserPrincipalName)" | |
$SendAs = (Get-RecipientPermission $Mailbox.DistinguishedName | ? {$_.AccessRights -match "SendAs" -and $_.Trustee -ne "NT AUTHORITY\SELF" -and !$_.Trustee.tostring().startswith('S-1-5-21-')} | select -ExpandProperty trustee) | |
$SendAs = ($SendAs | % {((get-mailbox $_).DisplayName)}) -join ";" | |
[string]$FullAccess = (Get-MailboxPermission $Mailbox.DistinguishedName | ? {$_.AccessRights -eq "FullAccess" -and !$_.IsInherited -and !$_.user.tostring().startswith('S-1-5-21-')} | Select -ExpandProperty User) -join "!!" | |
if ($fullaccess) { | |
$Fullaccess = (($FullAccess).split("!!") | % {((get-mailbox $_).DisplayName)}) -join ";" | |
} | |
<# | |
[string]$sendbehalf = (Get-Mailbox $Mailbox.DistinguishedName | select-object -ExpandProperty GrantSendOnBehalfTo) -join "!!" | |
if ($sendbehalf) { | |
$sendbehalf = (($sendbehalf).split("!!") | % {((get-mailbox $_).DisplayName)}) -join ";" | |
} | |
#> | |
if (!$SendAs -and !$FullAccess -and !$sendbehalf) {continue} | |
$Mailbox.DisplayName + "!" + $Mailbox.Alias + "!" + $Mailbox.OU + "!" + $Mailbox.UserPrincipalName + "!" + $FullAccess + "!" + $SendAs + "!" + $sendbehalf | Out-File $OutFile -Append -encoding ascii | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment