In this article, we’ll show how to get a date when a user or group was created in Azure AD or Microsoft 365 using PowerShell.
Connect to your Azure tenant:
Connect-AzureAD
Enter your username and password, confirm MFA sign-in (I’m using the Microsoft Authenticator app).
To get information about users in Azure, the Get-AzureADUser cmdlet is used. But there is no createdDateTime
attribute among user attributes returned by the cmdlet (unlike Get-ADUser able to return the value of whenCreated attribute from on-prem AD). You can display a list of available Azure AD user attributes as follows:
Get-AzureADUser -ObjectId "[email protected]"| Get-Member
To get information about extended Azure AD object attributes, use the Get-AzureADExtension cmdlet.
For example, to get the creation date of a user by their UserPrincipalName, run the command below:
(Get-AzureADUserExtension -ObjectId "f.m[email protected]").Get_Item("createdDateTime")
You can get the creation time of all users in your Azure AD tenant. Use this PowerShell script to do it:
$Report = @()
$AAD_users = Get-AzureADUser -All:$true
foreach ($AAD_User in $AAD_users) {
$objReport = [PSCustomObject]@{
User = $AAD_User.UserPrincipalName
CreationDate = (Get-AzureADUserExtension -ObjectId $AAD_User.ObjectId).Get_Item("createdDateTime")
}
$Report += $objReport
}
$Report
You can export the list of Azure AD users to a CSV file:
$Report| Export-CSV "$PSScriptRoot\aad_users.csv"
To get a date when a group in Azure AD was created, you will have to access your tenant using Microsoft Graph API (the connection method is described in the article “Connecting Azure via Microsoft Graph API and PowerShell”). To display group names and the dates when they were created, run the PowerShell script below:
$GrapGroupUrl = 'https://graph.microsoft.com/v1.0/Groups/'
$Groups=(Invoke-RestMethod -Headers @{Authorization = "Bearer $($token)"} -Uri $GrapGroupUrl -Method Get).value
$Groups | select displayName,createdDateTime