Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kevinblumenfeld/7466f8190ee674fee5d7bf5d1cf3e2b3 to your computer and use it in GitHub Desktop.
Save kevinblumenfeld/7466f8190ee674fee5d7bf5d1cf3e2b3 to your computer and use it in GitHub Desktop.
$OutFile = ".\365PermissionExport.csv"
"DisplayName" + "," + "Alias" + "," + "PrimarySMTP" + "," + "FullAccess" + "," + "SendAs" + "," + "SendonBehalf" | Out-File $OutFile -Force -encoding ascii
$Mailboxes = import-csv .\someupns.csv
# $Mailboxes = Get-Mailbox -ResultSize:Unlimited
ForEach ($Mailbox in $Mailboxes)
{
$SendAs = Get-RecipientPermission $Mailbox.PrimarySmtpAddress | ? {$_.AccessRights -match "SendAs" -and $_.Trustee -ne "NT AUTHORITY\SELF"} | % {$_.trustee}
$FullAccess = Get-MailboxPermission $Mailbox.PrimarySmtpAddress | ? {$_.AccessRights -eq "FullAccess" -and !$_.IsInherited} | % {$_.User}
$sendbehalf=Get-Mailbox $Mailbox.PrimarySmtpAddress | select-object -ExpandProperty GrantSendOnBehalfTo
if (!$SendAs -and !$FullAccess -and !$sendbehalf){continue}
$Mailbox.DisplayName + "," + $Mailbox.Alias + "," + $Mailbox.primarysmtpaddress + "," + $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