We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

Add owner names to group notes

February 24, 2021 Views: 1420

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
Leave a comment
Loading...

Got questions?

Support Questions & Answers