Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-MailboxSenders {
- <#
- .Synopsis
- Queries the allowed senders of a mailbox
- .DESCRIPTION
- Queries the senders who are allowed to send as a specified mailbox
- .EXAMPLE
- Get-MailboxSenders -Mailbox Charles.Curtis
- #>
- param (
- [Parameter(Mandatory=$true,HelpMessage='You must specify a mailbox')][string]$Mailbox
- )
- if(-not($Mailbox)) { Throw 'You must supply a mailbox to search' }
- Import-Module ActiveDirectory
- $ErrorActionPreference = 'Stop'
- try {$UserMailbox = Get-Mailbox $Mailbox -ErrorAction Stop }
- catch {
- Write-Error 'Could not find mailbox'
- }
- $alias = $UserMailbox.alias
- $senders = Get-Mailbox $UserMailbox.Alias | Get-ADPermission | Where-Object {($_.ExtendedRights -like '*send-as*') -and -not ($_.User -like '*nt authority*') -and -not ($_.User -like "*$alias") -and ($_.IsInherited -eq $false)}
- if ($senders.Count -lt '1'){
- Write-Host 'No senders were found' -ForegroundColor Yellow
- }
- foreach ($sender in $senders) {
- Get-ADUser $sender.User.SecurityIdentifier.ToString() -Properties *
- #Get-ADUser $account -Properties *
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement