Script Repository


Send notification to everybody who has Full Access to mailbox

October 29, 2019
173

The script sends an email notification to everybody who has Full Access to the target mailbox.

Parameters:

  • $subject - Specifies the email notification subject.
  • $message - specifies the email notification text.
Edit Remove
PowerShell
# E-mail settings
$subject = "My Subject" # TODO: modify me
$message = "My Message" # TODO: modify me

# Get Exchange properties
$mailboxParams = $Context.TargetObject.GetMailParameters()

# Get Full Access permissions
$objectReferences = $mailboxParams.MailboxRights.GetTrusteesGrantedRights("ADM_EXCHANGE_MAILBOX_RIGHTS_FULL_ACCESS")

foreach ($objectReference in $objectReferences)
{
    $sid = $objectReference.ObjectSid
    if ([System.String]::IsNullOrEmpty($sid))
    {
        continue
    }
    elseif ([Softerra.Adaxes.Utils.WellKnownSecurityPrincipalInfo]::IsWellKnown($sid))
    {
        continue
    }
    
    # Get object email
    try
    {
        # Bind to object
        $object = $Context.BindToObject("Adaxes://<SID=$sid>")
        $to = $object.Get("mail")
    }
    catch
    {
        continue
    }
    
    # Send mail
    $Context.SendMail($to, $subject, $message, $NULL)
}

Comments ( 0 )
No results found.
Leave a comment