Forum Discussion
Find all the AzureADUsers created after a certain date via PowerShell Graph
- Aug 13, 2022
Why the quote around the $Date ??
remove them and you are good.
$UsersCreatedDate | Where-Object {($_.CreatedDateTime -gt $Date)}
Also don't forget to include the all the required property in the Get-MgUser
Get-MgUser -UserId $_.Id -Property CreatedDateTime,JobTitle,UserPrincipalName,id
Why the quote around the $Date ??
remove them and you are good.
$UsersCreatedDate | Where-Object {($_.CreatedDateTime -gt $Date)}
Also don't forget to include the all the required property in the Get-MgUser
Get-MgUser -UserId $_.Id -Property CreatedDateTime,JobTitle,UserPrincipalName,id
- fstorerAug 14, 2022Brass ContributorThanks for pointing out that mistake! All works fine now and I was able to get my list!
- LainRobertsonAug 14, 2022Silver Contributor
You can leverage server-side filtering for this purpose rather than less-efficient client-side filtering.
The one thing to be wary of is that the supplied date needs to be in ISO 8601 format, which isn't clear from much of the docs.microsoft.com documentation (where the examples are plain wrong.)
This basic example searches shows how to find users created within the past year.
Get-MgUser -Filter "CreatedDateTime ge $([datetime]::UtcNow.AddYears(-1).ToString("s"))Z" | ft -AutoSize Id, UserPrincipalName, CreatedDateTime
Cheers,
Lain
- fstorerAug 14, 2022Brass Contributor
Many many thanks for your tip, it's indeed a lot faster! I also noticed that I have to select the "beta" MGProfile in order to see the CreatedDateTime.
This way I got immediately all the users created after a specific date (staff and students and shared mailboxes), is there a way to add a filter in that line and search ONLY members assigned to a specific Security Group (so I can get only the staff users)?
Many thanks again for your help!