CreatedOn
, CreatedAfter
, and CreatedBefore
parameters added in 1.2 to all Get-QAD* cmdlets are another new feature I would like to spotlight in my blog.
These can accept DateTime values or just strings which PowerShell can convert to such (automated type conversion in PowerShell is pretty cool.)
# Let's see all the new user accounts created since the 1st of the month Get-QADUser -CreatedAfter "April 1, 2009" # Can narrow it down to specific OU to exclude service accounts Get-QADUser -CreatedAfter "April 1, 2009" -SearchRoot mydomain.local/employees # Same thing for groups, computers, OUs, or any AD objects Get-QADComputer -CreatedAfter "April 1, 2009" Get-QADGroup -CreatedAfter "April 1, 2009" # Did we hire anyone today? Get-QADUser -CreatedOn "April 17, 2009" # Let's if we have anyone who is with the company for more than 10 years ;) Get-QADUser -CreatedBefore (Get-Date).AddYears(-10) -SearchRoot d.local/emp -Enabled # Let's count how many employees we were hiring monthly for ($d = Get-Date "January 1, 2008"; $d -le (Get-Date); $d = $d.AddMonths(1)) { "$($d.ToShortDateString()) to $($d.AddMonths(1).ToShortDateString()):" (Get-QADUser -CreatedAfter $d -CreatedBefore $d.AddMonths(1)).Count }
And you can use other parameters to get the data by department, city, title, and so on!
Now go to your HR and ask them if they can provide data like that so quickly. 😉
Tags: AD, AD cmdlets, Active Directory, Examples, PowerShell, cmdlets, one-liner
How about who’s been disabled during a time window?
Actually, I found a way. My temination script disables the acct, moves them into a ‘disabled’ OU, and modifies the description to state when the acct was disabled.
So this worked nicely;
get-qaduser -searchroot ‘domain/Disabled Users’ -disabled
-description ‘disabled 4/*/2009’| ft name, description
Now I can find the disabled users quickly and match them against the term report from HR.
For created today, you can use the (get-date) function:
Get-QADUser -CreatedOn (get-date)