Script Repository


Add owner names to group notes

February 05, 2020
180

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.

Edit Remove
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()


Comments ( 0 )
No results found.
Leave a comment