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

Users with upcoming anniversaries

August 22, 2022 Views: 463

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.
Edit Remove
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() }
}
Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers