Hello,
You will need to create a Scheduled Task configured for Domain-DNS object type that will execute the below script. For information on how to create Scheduled Tasks, have a look at the following tutorial: https://www.adaxes.com/tutorials_Automa ... gement.htm. On step 3 of the tutorial, select Show all object types and then select Domain-DNS Object type.
In the script:
- $propertyName - specifies the LDAP name of the property storing the decommission date;
- $to - specifies the email address of the notification recipient;
- $subject - specifies the notification subject.
$propertyName = "adm-CustomAttributeDate1" # TODO: modify me
# E-mail settings
$to = "recipient@domain.com" # TODO: modify me
$subject = "Users report" # TODO: modify me
function SearchObjects($filter, $properties)
{
$searcher = $Context.BindToObject("Adaxes://rootDSE")
$searcher.SearchFilter = $filter
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.PageSize = 500
$searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
$searcher.SetPropertiesToLoad($properties)
$searcher.VirtualRoot = $True
try
{
$searchResultIterator = $searcher.ExecuteSearch()
$searchResults = $searchResultIterator.FetchAll()
return ,$searchResults
}
finally
{
# Release resources
if ($searchResultIterator){ $searchResultIterator.Dispose() }
}
}
# Search users
$searchResults = SearchObjects "(sAMAccountType=805306368)" @($propertyName, "name")
$firstList = New-Object "System.Text.StringBuilder"
$secondList = New-Object "System.Text.StringBuilder"
$firstDate = [System.DateTime]::Now.AddDays(-30)
$secondDate = [System.DateTime]::Now.AddDays(-45)
foreach ($searchResult in $searchResults)
{
if (-not($searchResult.ContainsProperty($propertyName)))
{
continue
}
$date = $searchResult.Properties[$propertyName].Value
if ($date.Date -eq $firstDate.Date)
{
[void]$firstList.AppendLine($searchResult.Properties["name"].Value)
}
elseif ($date.Date -eq $secondDate.Date)
{
[void]$secondList.AppendLine($searchResult.Properties["name"].Value)
}
}
# Build message
if (($firstList.Length -eq 0) -and ($secondList.Length -eq 0))
{
$message = "Now users found"
}
else
{
$message = New-Object "System.Text.StringBuilder"
if ($firstList.Length -ne 0)
{
[void]$message.AppendLine("Please complete the 30 Day decommission process for the following users")
[void]$message.AppendLine()
[void]$message.Append($firstList.ToString())
[void]$message.AppendLine()
}
if ($secondList.Length -ne 0)
{
[void]$message.AppendLine("Please complete the 45 Day decommission process for the following users:")
[void]$message.AppendLine()
[void]$message.Append($secondList.ToString())
}
}
# Send mail
$Context.SendMail($to, $subject, $message.ToString(), $NULL)