1

I am new to PowerShell and am looking to do something and am not able to figure it out, so naturally I turn to the experts over here. I don't know if it makes a difference, but I will be using Cloud Shell to run this operation.

I am needing to gather a list of all users on my AzureAD environment and collect two pieces of information. The first is a users Display Name or UPN, and the second is an extended attribute (we will call this EA1). After I have that I will need to move it into a CSV so I can send it off.

What I have found so far are two commands that I believe I would need to combine.

Get-AzureADUser | Select displayName
(Get-AzureADUserExtension).get_item("ea1")

Both of those commands will get me the overall information that I am looking for, but I will need to combine/correlate it.

I feel like I will need to set these to variables but I am not 100% sure on this.

Any assistance on this would be much appreciated.

2 Answers2

0

To reach your requirement, try the below steps if they are helpful:

  • To get list of all Azure AD users, make use of below cmdlet:
$AAD_users = Get-AzureADUser -All:$true 
  • To get the specific properties of all users, make use of foreach loop.
  • To expand Extension Attributes related to the user convert Dictionary to Custom Object so that we can use dot (.) operator to access the keys.
  • In this, I have retrieved createdDateTime extension attribute. You can replace it with EA1
  • To Combine both the regular attributes and extension attributes to a single object and to move all the information to a CSV, make use of below script:
$Info = @()
$AAD_users = Get-AzureADUser -All:$true
foreach ($AAD_User in $AAD_users) {
$objInfo = [PSCustomObject]@{
User     = $AAD_User.UserPrincipalName
Name     = $AAD_User.DisplayName
CreationDate  = (Get-AzureADUserExtension -ObjectId $AAD_User.ObjectId).Get_Item("createdDateTime")
}
$Info += $objInfo
}
$Info
Export-csv -Path c:\File.csv -NoTypeInformation -Force -Append

enter image description here

enter image description here

Reference:

Get-AzureADExtension attribute for all AzureAD users

python - How to export Extension Attributes from Azure AD to csv using Powershell - Stack Overflow

Sridevi
  • 10,599
  • 1
  • 4
  • 17
0

It looks likes get-azureaduser returns all the extended properties anyway in a case sensitive dictionary. Note that createdDateTime is only a string.

Get-AzureADUser | select displayname, 
  @{n='createdDateTime';e={[datetime]$_.extensionproperty['createdDateTime']}}

DisplayName  createdDateTime
-----------  ---------------
js2010       1/16/2016 1:40:21 PM
js2010
  • 23,033
  • 6
  • 64
  • 66