Message approval

This code sample retrieves the following message approval settings of a mail-enabled group:

  • Message moderation
  • Moderators
  • Senders who don't require message approval
  • Notifications to senders of unapproved messages

In the below code sample, the $groupParams variable represents Exchange properties of a mail-enabled group. To retrieve the properties, use the IAdmExchangeMailParametersOps::GetMailParameters method.

 How
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

# Bind to the group
$groupDN = "CN=My Group,CN=Groups,DC=domain,DC=com"
$group = $service.OpenObject("Adaxes://$groupDN", $null, $null, 0)

# Get Exchange properties
$groupParams = $group.GetMailParameters()
# The $groupParams variable represents Exchange properties of a mail-enabled group

# Get message moderation settings
$messageModeration = $groupParams.MailFlowSettings.MessageModeration

# Moderation enabled
Write-Host "Messages sent to this group have to be approved by a moderator:" $messageModeration.ModerationEnabled

# Moderators
$moderators = $messageModeration.ModeratedBy

if ($moderators.Count -eq 0)
{
    Write-Host "Moderators: The group owner will review and approve messages"
}
else
{
    Write-Host "Moderators:"
    for ($i = 0; $i -lt $moderators.Count; $i++)
    {
        $object = $moderators.GetItem($i, [ref]"ADS_PROPERTY_NONE")
        Write-host "`t" $object.DisplayName
    }
}

# Senders who don't require message approval
$bypassModerationFrom = $messageModeration.BypassModerationFrom

if ($bypassModerationFrom.Count -eq 0)
{
    Write-Host "Senders who don't require message approval: None"
}
else
{
    Write-Host "Senders who don't require message approval:"
    for ($i = 0; $i -lt $bypassModerationFrom.Count; $i++)
    {
        $object = $bypassModerationFrom.GetItem($i, [ref]"ADS_PROPERTY_NONE")
        Write-host "`t" $object.DisplayName
    }
}

# Notifications to senders of unapproved messages
$sendModerationNotificationType = $messageModeration.SendModerationNotificationType
Write-Host "Notifications: " -NoNewline
switch ($sendModerationNotificationType)
{
    "ADM_EXCHANGE_SENDMODERATIONNOTIFICATIONTYPE_NEVER"
    {
        Write-Host "Don't notify anyone when their messages aren't approved"
    }
    "ADM_EXCHANGE_SENDMODERATIONNOTIFICATIONTYPE_INTERNAL"
    {
        Write-Host "Notify senders in your organization when their messages aren't approved"
    }
    "ADM_EXCHANGE_SENDMODERATIONNOTIFICATIONTYPE_ALWAYS"
    {
        Write-Host "Notify all senders when their messages aren't approved"
    }
}

See also