Script Repository

All managed objects

February 18, 2021

The script emails a list of Active Directory objects managed by the user that the script is executed on. This includes all objects that have the user specified either in the Manager or in the Managed By attribute.

To be able to create such a report on request, you will need to create a custom command that executes the script on User objects.


  • $to - Specifies the recipient(s) of the report.
  • $subject - Specifies the subject of the e-mail message.
  • $reportHeader - Specifies the email message header (in HTML format).
  • $reportFooter - Specifies the email message footer (in HTML format).
Edit Remove
# Email message settings
$to = "" # TODO: modify me
$subject = "My Subject" # TODO: modify me
$reportHeader = "<h1><b>Objects Managed by %name%</b></h1><br/>" # TODO: modify me
$reportFooter = "<hr /><p><i>Please do not reply to this e-mail, it has been sent to you for notification purposes only.</i></p>" # TODO: modify me

# Get the default Web Interface address
$webInterfaceAddress = "%adm-WebInterfaceUrl%"
if ([System.String]::IsNullOrEmpty($webInterfaceAddress))
    $Context.LogMessage("Default web interface address not set for Adaxes service. For details, see", "Warning")

# Get all direct reports
    $directReports = $Context.TargetObject.GetEx("directReports")
    $directReports = $NULL
    $subordinates = "The user doesn't have any direct reports.<br />"

# Get names of all the direct reports and add them to the report
if ($directReports -ne $NULL)
    $subordinates = "<b>Direct Reports:</b><br /><ol>"
    foreach ($directReport in $directReports)
        # Bind to user
        $user = $Context.BindToObjectByDN($directReport)
        # Get username and GUID
        $username = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName($user, 'IncludeParentPath')
        $userGuid = [Guid] $user.Get("ObjectGuid")
        # Add to report
        $subordinates += "<li><a href='$webInterfaceAddress`ViewObject.aspx?guid=$userGuid'>$username</a></li>"
    $subordinates += "</ol>"

# Get all managed objects
    $managedObjectDNs = $Context.TargetObject.Get("managedObjects")
    $managedObjectDNs = $NULL
    $managedObjects = "The user doesn't have any managed objects."

# Get names of all managed objects and add them to the report
if ($managedObjectDNs -ne $NULL)
    $managedObjects = "<b>Managed objects:</b><br /><ol>"
    foreach ($managedObjectDN in $managedObjectDNs)
        # Bind to object
        $object = $Context.BindToObjectByDN($managedObjectDN)
        # Get object name and GUID
        $objectName = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName($object, 'IncludeParentPath')
        $objectGuid = [Guid] $object.Get("ObjectGuid")
        # Add to report
        $managedObjects += "<li><a href='$webInterfaceAddress`ViewObject.aspx?guid=$objectGuid'>$objectName</a></li>"
    $managedObjects += "</ol>"

# Build the report
$report = $reportHeader + $subordinates + $managedObjects + $reportFooter

# Send mail
$Context.SendMail($to, $subject, $NULL, $report)

Comments ( 0 )
No results found.
Leave a comment