Home > database >  Unable to retrieve createdDateTime along with mail,displayName of Azure AD Users
Unable to retrieve createdDateTime along with mail,displayName of Azure AD Users

Time:04-22

I am trying to retrieve createdDateTime of Azure AD Users along with their Name and email address.

I found below commands:

  • To connect to Azure AD: Connect-AzureAD
  • To retrieve the list of AzureAD users: Get-AzureADUser
  • To retrieve specific attributes, I tried using below command:
Get-AzureADUser | Select-Object DisplayName, Mail, createdDateTime

It is returning name and email of users successfully. But createdDateTime field is always empty for all users. I don't know where the problem is.

After retrieving all these, I want to export data to a CSV file that contains info like user's displayName, mail and their createdDateTime.

Can anyone help me out with the script or any suggestions?

Thanks in advance.

CodePudding user response:

Please note that createdDateTime is an extension attribute. That's why it won't be displayed normally.

In order to display createdDateTime of Azure AD Users along with their name and email address, make use of below script:

$Info = @()
$AAD_users = Get-AzureADUser -All:$true
foreach ($AAD_User in $AAD_users) {
$objInfo = [PSCustomObject]@{
Name     = $AAD_User.DisplayName
Email     = $AAD_User.mail
CreationDateTime  = (Get-AzureADUserExtension -ObjectId $AAD_User.ObjectId).Get_Item("createdDateTime")
}
$Info  = $objInfo
}
$Info

enter image description here

To export all this information to an CSV file, make use of below cmdlet:

$Info | Export-csv -Path c:\Output.csv -NoTypeInformation -Force -Append

enter image description here

To know more in detail, please find below reference:

powershell - Gathering a list of both Standard Attr. and Extended attr. for Azure - Stack Overflow

  • Related