This snippet can be used for easier date formatting when using an LDAP date filter with PowerShell. This demonstrates how to get users created within the previous 30 days using LDAP:
$MaxDays = 30 $StartDate = (Get-date).AddDays(-$MaxDays) #Set to begin at midnight $ldapStart = $StartDate.GetDateTimeFormats()[5].ToString().Replace("-",'')+'000000.0Z' $LDAPFilter = "(WhenCreated>=$ldapStart)" Get-aduser -LDAPFilter $ldapfilter -properties whencreated