The script generates a report containing users whose yearly anniversary is within the specified period. For information on how to create reports, see https://www.adaxes.com/tutorials_ActiveDirectoryManagement_CreateReport.htm.
Parameters:
- $startDateProperty - Specifies the LDAP name of the property storing the dates to check.
- $days - Specifies the number of days to check anniversaries for.
PowerShell
$startDateProperty = "adm-CustomAttributeDate1" # TODO: modify me
$days = 10 # TODO: modify me
$today = [DateTime]::UtcNow
# Add the property to the list of properties to fetch
$Context.DirectorySearcher.SearchParameters.PropertiesToLoad.Add($startDateProperty)
try
{
$searchIterator = $Context.DirectorySearcher.ExecuteSearch()
while ($Context.MoveNext($searchIterator))
{
$searchResult = $searchIterator.Current
$startDate = $searchResult.GetPropertyByName($startDateProperty).Values[0]
$result = $startDate.DayOfYear - $today.DayOfYear
if ($result -le $days -and $result -gt 0)
{
$Context.Items.Add($searchResult)
}
}
}
finally
{
# Release resources
if ($searchIterator) { $searchIterator.Dispose() }
}