Skip to content

Delegation

The following code sample retrieves the following permissions on a mail-enabled group:

  • Send As delegates
  • Send on Behalf Of delegates

Note

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
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

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

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

# Send As delegates
$sendAs = $groupParams.SendAs
if ($sendAs.Count -eq 0)
{
    Write-Host "Send As: Not delegated"
}
else
{
    Write-Host "Send As:"
    for ($i = 0; $i -lt $sendAs.Count; $i++)
    {
        $object = $sendAs.GetItem($i, [ref]"ADS_PROPERTY_NONE")
        Write-host "`t" $object.DisplayName
    }
}

# Send on Behalf Of delegates
$sendOnBehalfOf = $groupParams.GrantSendOnBehalfTo
if ($sendOnBehalfOf.Count -eq 0)
{
    Write-Host "Send on Behalf Of: Not delegated"
}
else
{
    Write-Host "Send on Behalf Of:"
    for ($i = 0; $i -lt $sendOnBehalfOf.Count; $i++)
    {
        $object = $sendOnBehalfOf.GetItem($i, [ref]"ADS_PROPERTY_NONE")
        Write-host "`t" $object.DisplayName
    }
}

See also