The script adds names of the group owner stored in the managedBy property and co-owners stored in the msExchCoManagedByLink property to the Notes property of the group. To run the script, you can create a custom command configured for the Group object type.
PowerShell
# Get group owner
try
{
$ownerDN = $Context.TargetObject.Get("managedBy")
}
catch
{
$ownerDN = $NULL
}
# Get group co-managers
try
{
$coManagerDNs = $Context.TargetObject.GetEx("msExchCoManagedByLink")
}
catch
{
$coManagerDNs = $NULL
}
# Build notes
$notes = New-Object "System.Text.StringBuilder"
$notes.Append("Owner: ")
if ($ownerDN -ne $NULL)
{
$owner = $Context.BindToObjectByDN($ownerDN)
$ownerName = $owner.Get("name")
$notes.Append($ownerName)
}
else
{
$notes.Append("<not set>")
}
$notes.AppendLine()
$notes.Append("Backup Owner: ")
if ($coManagerDNs -ne $NULL)
{
foreach ($dn in $coManagerDNs)
{
$manager = $Context.BindToObjectByDN($dn)
$managerName = $manager.Get("name")
$notes.Append("$managerName")
$notes.Append(", ")
}
}
else
{
$notes.Append("<not set>")
}
# Update group
$Context.TargetObject.Put("info", $notes.ToString().TrimEnd(", "))
$Context.TargetObject.SetInfo()