PowerShell: Get created date for Microsoft 365/Azure AD users

Recently I had a need in a project to get the dates that users were created/added to Microsoft 365, so it would be possible to get some statistics on how many users were added per period. As the number of users was not that big, the quicker solution was to figure out a way using Azure AD PowerShell.

Prerequisite

Azure AD Powershell module installed.

The simpler solution

Unfortunately, the Get-AzureADUser cmdlet doesn’t bring the created date info.

Another cmdlet can be used in combination with the one mentioned above: Get-AzureADExtension.

With the Get-AzureADExtension we can get additional properties for a single user. By combining both, it’s possible to get the values for all the users in a single script.

Syntax for getting the created date for a single user:

(Get-AzureADUserExtension -ObjectId "UserID").Get_Item("createdDateTime") 

To get the created date for all users and export the data to a CSV file located in the same folder where your script is saved, you can use the following script:

Connect-AzureAD 

$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent 

$usrs = Get-AzureADUser -All:$true 

$usrs | ForEach-Object{

    Write-Host “Getting created date for” $_.UserPrincipalName

    $_ | Add-Member -MemberType NoteProperty -Name "CreatedDateTime" `

    -Value (Get-AzureADUserExtension -ObjectId $_.ObjectId).Get_Item("createdDateTime")

} 

$usrs | Export-CSV "$PSScriptRoot\userslist.csv" 

Disconnect-AzureAD 

This script will retrieve the list of users, iterates through each of them, adds a property “CreatedDateTime” with the created date value obtained with the Get-AzureADUserExtension cmdlet and finally exports it to a CSV file.

Considerations

As the script iterates through the list of all Azure AD users and executes a request to get the extensions and created date for each, it’ll be a heavy operation. In my case, as it was a single execution for a tenant with around 5000 users only, I didn’t worry much about performance (it took a few minutes to finish executing), but be aware of potential performance/throttling issues for a tenant with a large number of users.

13 comments

    1. Hi, not with Azure AD PowerShell as far as I know, we would need to use the Microsoft Graph PowerShell library for that…

  1. Do you know if Get_Items (plural) or similar exists? I can’t find a method to get multiple extension attributes in one go. Seems inefficient to call upon the cmdlet multiple times.

    Thanks

    1. No, unfortunately not…That’s why I stated it can be a heavy one as it iterates through all users and makes a call for each

  2. I’m getting this when I run the script. “The Value parameter is required for a member of type “NoteProperty”. Specify the Value parameter when adding members of this type.” What should the Value be?

    1. Put the piece of code -Value (Get-AzureADUserExtension -ObjectId $_.ObjectId).Get_Item(“createdDateTime”)
      in the same line as -Name “CreatedDateTime”
      And delete the char: `

      In some clients that might cause the issue

  3. Awesome! Thank you for this blog post.
    It really helped me today creating script based report of our users and their creation date.

  4. Thanks for this. Newb here

    The script is running through every user in our tenant. I just changed this line to the file location:

    $usrs | Export-CSV “$PSScriptRoot\C:\_IT\Scripts\Guest User\Get_create_date.csv”

Comments are closed.