Hello forum helper!
I have created a powershell with obtain some info from AzureAD User but it seems to run slowly.
I would like help to speed up this code. I have 80000 users and takes more or less 3 hours to run
Thank you in advance
#Gettting the User from the AAD
$all = get-azureaduser -All $true
$all | foreach-object {
$user = $_
#Expanding only the Extenstion Attributes related to the user and converting the Dictionary to Custom Object so that keys can be accessed through the dot (.) operator
$Extension_Attributes = New-Object Psobject -Property $user.ExtensionProperty
#Combining the required attributes from the user object and extension_attributes to A single object
$u_properties = [pscustomobject] @{
"ObjectID"= $user.ObjectId
"Status" = $user.AccountEnabled
"DisplayName" = $user.DisplayName
"UserPrincipalName" = $user.UserPrincipalName
"State" = $user.State
"Country" = $user.Country
"Company" = $user.CompanyName
"City" = $user.City
"EmployeeType" = $Extension_Attributes.extension_051b51b4f48a430aaeaac8d3f42b050a_employeeType
"Mail" = $user.Mail
"UsageCountry" = $user.UsageLocation
"onPremisesDistinguishedName" = $Extension_Attributes.onPremisesDistinguishedName
"Created" = $Extension_Attributes.createdDateTime
"CompanyCode" = Get-ADUser -identity $Extension_Attributes.onPremisesDistinguishedName -Properties * | Select -Property extensionAttribute1, extensionAttribute11, extensionAttribute14
"ManagerID" = Get-AzureADUserManager -ObjectId $user.ObjectId | Select -ExpandProperty ObjectId
}
#Exporting the object to a file in an append fashoin
$u_properties | Export-Csv -Path C:\Users\xxxxxx\Documents\PowerBI\Users.csv -Append -NoTypeInformation -Encoding UTF8
}