2

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?

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
  • that indicates that there is NO such property in the original objects. [*grin*] leave off the pipe & see what properties are actually there ... and then chose the correct one for export. – Lee_Dailey Apr 20 '22 at 17:33

1 Answers1

1

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

Sridevi
  • 10,599
  • 1
  • 4
  • 17