Advertisement
rcurtis12

Get-MailboxSenders

Sep 25th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-MailboxSenders {
  2.  
  3. <#
  4.     .Synopsis
  5.     Queries the allowed senders of a mailbox
  6.  
  7.     .DESCRIPTION
  8.     Queries the senders who are allowed to send as a specified mailbox
  9.  
  10.     .EXAMPLE
  11.     Get-MailboxSenders -Mailbox Charles.Curtis
  12. #>
  13.  
  14.   param (
  15.     [Parameter(Mandatory=$true,HelpMessage='You must specify a mailbox')][string]$Mailbox
  16.     )
  17.   if(-not($Mailbox)) { Throw 'You must supply a mailbox to search' }
  18.  
  19.   Import-Module ActiveDirectory
  20.  
  21.   $ErrorActionPreference = 'Stop'
  22.   try {$UserMailbox = Get-Mailbox $Mailbox -ErrorAction Stop }
  23.   catch {
  24.     Write-Error 'Could not find mailbox'
  25.     }
  26.  
  27.   $alias = $UserMailbox.alias
  28.   $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)}
  29.   if ($senders.Count -lt '1'){
  30.     Write-Host 'No senders were found' -ForegroundColor Yellow
  31.   }
  32.   foreach ($sender in $senders) {
  33.     Get-ADUser $sender.User.SecurityIdentifier.ToString() -Properties *
  34.     #Get-ADUser $account -Properties *
  35.    }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement