Hi All, I was wondering, is there a way to find out the history how many users were created in Active Directory for a specific year, Or is there a third party tool that can achive this?
Thanks
Hi All, I was wondering, is there a way to find out the history how many users were created in Active Directory for a specific year, Or is there a third party tool that can achive this?
Thanks
$yearCreated = Read-Host "Enter the year"
Get-ADUser -filter * -Properties whenCreated | where {($_.whencreated).year -eq $yearCreated} | measure-object | select count
Mike Rodrick
Edutainer, ITProTV
**if the post above has answered the question, please mark the topic as solved.
or
$yearCreated = Read-Host "Enter the year"
(Get-ADUser -filter * -Properties whenCreated | where {($_.whencreated).year -eq $yearCreated}).count
Mike Rodrick
Edutainer, ITProTV
**if the post above has answered the question, please mark the topic as solved.
@Mike-Rodrick Thanks for the script.
I have just tested the second script and though it shows a number, it doesn't seem to be correct regarding how many users were created.
Is this script resulting more than just users maybe? Also, is there a way to find out how many users we had for the end of the total year?
Thanks
@Mike-Rodrick So I have found the following script;
$When = ((Get-Date).AddDays(-365)).Date
Get-ADUser -Filter {whenCreated -ge $When} -Properties whenCreated
I was wondering, how can I edit to just find specific dates, e.g. from Feb/2018 to Feb/2019
Because built-in accounts are based on the user objectClass, they are included in the count. You would need to know how many you had and subtract this (it would be a static number that could be included in the script, Administrator, guest, defaultAccount, etc) or you could filter by RID, user created objects have a RID greater than 1000.
The script you found uses the same whenCreated property, so it should produce the same count (including built-in accounts). The difference is it counts back one year from today's date for the range.
If you want to provide your own date range dynamically, just prompt for the start and end date, using Read-Host. You could also just prompt for an end date and then subtracts 365 to get one years worth of data.
Mike Rodrick
Edutainer, ITProTV
**if the post above has answered the question, please mark the topic as solved.
This will return the RID portion of a users SID
Get-ADUser -f * | % {$_.sid.tostring().split(“-“)[7]}
Mike Rodrick
Edutainer, ITProTV
**if the post above has answered the question, please mark the topic as solved.
PowerShell doesn't have a between comparison operator, to to return users created between a date range, you will have to use an and operator. Something like
whenCreated -ge $startDate -and whenCreated -le $endDate
Mike Rodrick
Edutainer, ITProTV
**if the post above has answered the question, please mark the topic as solved.
You could also limit the scope of the script to a particular OU (or OUs) to prevent the count from including built-in user accounts.
Mike Rodrick
Edutainer, ITProTV
**if the post above has answered the question, please mark the topic as solved.