I have many users in my Azure AD tenant, I want to collect the data of the users when they are created.
I am able to get the user details by running Get-AzureADUser
. So, I just modified the command as
Get-AzureADUser | Select-Object, Mail, createdDateTime
But this returned details but the createdDateTime field was empty. After some research I found that createdDateTime is an extension attribute.
I found this command Get-AzureADUserExtension
but now my question is I want to get the list of users with their email and the created date time.
Any script to achieve my scenario?
TIA
CodePudding user response:
I am not using the Az Module as its end-of-life is not that far away anymore. It got replaced by the mgGraph cmdlets (install-module microsoft.graph).
There I can do:
get-mguser -Filter "userPrincipalName eq '[email protected]'" -Property CreatedDateTime,Mail,UserPrincipalName
The property CreatedDateTime does not need to be expanded but it must be explicitly listed as property to retrieve, otherwise I won't get the value. I think you can do simliar with the Az cmdlets or otherwise switch to the MgGraph cmdlets which you have to do anyways until 2024.
CodePudding user response:
I tried to reproduce the same in my environment and got the results successfully like below:
To get the createdDateTime
of Azure AD Users with email address, I tried the below script:
$result = @()
$AAD_users = Get-AzureADUser -All:$true
foreach ($AAD_User in $AAD_users) {
$info = [PSCustomObject]@{
Email = $AAD_User.mail
CreationDateTime = (Get-AzureADUserExtension -ObjectId $AAD_User.ObjectId).Get_Item("createdDateTime")
}
$result = $info
}
$result
I am able to get the list of users with createdDateTime
successfully like below: