Update 2018
Starting with version 2018.1, you can create custom reports and make them available in the Web interface. For details, have a look at the following tutorial: https://www.adaxes.com/tutorials_ActiveDirectoryManagement_CreateReport.htm.
Original
Hello Carole,
The following script builds the request that you requested and sends it by e-mail. Script parameters:
- $to - specifies email addresses of the recipient(s) of the report;
- $subject - specifies the email message subject;
- $reportHeader - specifies the email message header;
- $reportFooter - specifies the email message footer.
To run the report on demand, create a Custom Command for the Domain-DNS object type and execute it on any of your AD domains. To schedule it, you need to create a Scheduled Task configured for the Domain-DNS object type. To add the script to a Custom Command or Scheduled Task, use the Run a program or PowerShell script action.
$to = "recipient@domain.com" # TODO: modify me
$subject = "Management Report" # TODO: modify me
$reportHeader = "<h2><b>List of User Managers by Department and Section</b></h2>" # 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
# Search users
$searcher = $Context.BindToObject("Adaxes://rootDSE")
$searcher.SearchFilter = "(&(sAMAccountType=805306368)(department=*)(description=*))"
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.PageSize = 500
$searcher.SetPropertiesToLoad(@("department", "description", "manager", "objectGuid"))
$searcher.VirtualRoot = $True
try
{
$searchResult = $searcher.ExecuteSearch()
$users = $searchResult.FetchAll()
# Build department and section list
$departmentList = @{}
foreach ($userId in $users)
{
# Update department list
$department = $userId.Properties["department"].Value
$section = $userId.Properties["description"].Value
if (!($departmentList.ContainsKey($department)))
{
$departmentList.Add($department, @{})
}
# Update section list
$sectionList = $departmentList[$department]
if (!($sectionList.ContainsKey($section)))
{
$sectionList.Add($section, @{})
}
# Get manager name
$managerDN = $userId.Properties["manager"].Value
if ($managerDN -ne $NULL)
{
$managerPath = New-Object -TypeName "Softerra.Adaxes.Adsi.AdsPath" -ArgumentList @($null, $managerDN)
$managerDisplayName = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName($managerPath, "IncludeParentPath")
}
else
{
$managerDisplayName = "No manager"
}
# Update manager list
$userDisplayName = $Context.GetDisplayNameFromAdsPath($userId.AdsPath)
$guid = [Guid]$userID.Properties["objectGUID"].Value
$userLink = "<ul><a href='$webInterfaceAddress`ViewObject.aspx?guid=$guid'>$userDisplayName</a></ul>"
$managerList = $sectionList[$section]
if ($managerList.ContainsKey($managerDisplayName))
{
$managerList[$managerDisplayName] += $userLink
}
else
{
$managerList.Add($managerDisplayName, @($userLink))
}
}
}
finally
{
$searchResult.Dispose()
}
# Build report
# 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 http://www.adaxes.com/help/?HowDoI.ManageService.RegisterWebInterface.html", "Warning")
}
$reportHeader += "<ol>"
foreach ($department in $departmentList.Keys)
{
# Add department to the report
$reportHeader += "<ul><b>$department</b></ul>"
$sectionList = $departmentList[$department]
$reportHeader += "<ol>"
foreach ($section in $sectionList.Keys)
{
# Add section to the report
$reportHeader += "<ul><b>$section</b></ul>"
$managerList = $sectionList[$section]
$reportHeader += "<ol>"
foreach ($managerDisplayName in $managerList.Keys)
{
# Add manager to the report
$reportHeader += "<ul><b>$managerDisplayName</b></ul><ol>"
# Add users to the report
$reportHeader += $managerList[$managerDisplayName]
$reportHeader += "</ol><br/>"
}
$reportHeader += "</ol>"
}
$reportHeader += "</ol>"
}
$reportHeader += "</ol>"
# Send report
$htmlReport = $reportHeader + $reportFooter
$Context.SendMail($to, $subject, $NULL, $htmlReport)