Arbelac
Arbelac

Reputation: 1904

How to retrieve the employeeid attribute

How to retrieve the employeeid attribute? I do not get any output when I execute:

Get-AzureADUser -ObjectId "[email protected]" | Select-Object -ExpandProperty ExtensionProperty

Key                         Value
---                         -----
odata.metadata              https://graph.windows.net/xxxxxxxxxxx-xxxx-xxxxxxxxxxxx/$metadata#directoryObjects/Mic...
odata.type                  Microsoft.DirectoryServices.User
employeeId                  118880
onPremisesDistinguishedName
userIdentities              []

I do not know how to retrieve it with AzureAD PowerShell.

Get-AzureADUser -ObjectId "[email protected]" | Select-Object employeeId

employeeId
----------

Last update:

$_default_log = $env:userprofile + '\Documents\azuread_enabled_accounts.csv'
Get-AzureADUser -All $true -Filter 'accountEnabled eq true' |
    select DisplayName, UserPrincipalName, Mail, Department, UserType,
        CreationType, RefreshTokensValidFromDateTime, AccountEnabled,
        @{name='Licensed';expression={if($_.AssignedLicenses){$TRUE}else{$False}}},
        @{name='Plan';expression={if($_.AssignedPlans){$TRUE}else{$False}}},ObjectId |
    Export-Csv $_default_log -NoTypeInformation -Encoding UTF8

Upvotes: 0

Views: 20556

Answers (1)

Avshalom
Avshalom

Reputation: 8889

It's Dictionary/HashTable which is a Key/Value pairs object, so Try:

(Get-AzureADUser -ObjectId "[email protected]").ExtensionProperty["employeeId"]

Using your Example, added as last property:

$_default_log = $env:userprofile + '\Documents\azuread_enabled_accounts.csv'
get-azureaduser -all $true -filter 'accountEnabled eq true' | select DisplayName,`
UserPrincipalName,Mail,Department,UserType,CreationType,RefreshTokensValidFromDateTime,AccountEnabled,`
@{name='Licensed';expression={if($_.AssignedLicenses){$TRUE}else{$False}}},`
@{name='Plan';expression={if($_.AssignedPlans){$TRUE}else{$False}}},ObjectId, `
@{N="EmployeeId";E={$_.ExtensionProperty["employeeId"]} } | export-csv $_default_log -NoTypeInformation -Encoding UTF8

Upvotes: 2

Related Questions