Is it possible to list extensionAttribute1 - extensionAttribute15 via PowerShell command?

Viewed 7333

I am trying to find out for a client if it is possible to list onPremisesExtensionAttributes with a complex type which contains the extensionAttribute1 - extensionAttribute15 for cloud based users. Here is the summary:

In the test is used Graph API beta. The user resource type has a property named onPremisesExtensionAttributes with a complex type which contains the extensionAttribute1 - extensionAttribute15

we used MS GRAPH PATCH to update the extensionAttribute1 - extensionAttribute15

We've tested this by setting extensionAttribute1 to a test value 'xxxxTestValue'.

Remark: we do not sync on premise AD. We've set the value of the extensionAttribute1 with the MS Graph API PATCH operation.

How can we set the extensionAttribute1 - extensionAttribute15 with a PowerShell command?

Is it possible with a PowerShell command or is the only way to use MS Graph?

We tested the output in this article: https://docs.microsoft.com/en-us/powershell/azure/active-directory/using-extension-attributes-sample?view=azureadps-2.0

and received the results below:

PS Azure:\> Get-AzureADUser -ObjectId xxxxxxxxxx | Select -ExpandProperty ExtensionProperty

Key                                Value
---                                -----
odata.metadata                     https://graph.windows.net/xxxxxxxxxxxxxxxxxxxx
odata.type                         Microsoft.DirectoryServices.User
createdDateTime                    3/20/19 3:28:08 PM
employeeId
onPremisesDistinguishedName
thumbnailPhoto@odata.mediaEditLink directoryObjects/e98f0e1a-677c-4974-9a2d-31cbb987fb69/Microsoft.DirectoryServices.User/thumbnailPhoto
userIdentities                     []

Testing this with MS Graph Explorer gives:

Request:

https://graph.microsoft.com/beta/users/usernamexxx?$select=onPremisesExtensionAttributes

Response:

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#usersxxxxxxx(onPremisesExtensionAttributes)/$entityxxxxxxxxx",
    "onPremisesExtensionAttributes": {
        "extensionAttribute1": "xxxxxTestValue",
        "extensionAttribute2": "something else",
        "extensionAttribute3": "another thing",
        "extensionAttribute4": null,
        "extensionAttribute5": null,
        "extensionAttribute6": null,
        "extensionAttribute7": null,
        "extensionAttribute8": null,
        "extensionAttribute9": null,
        "extensionAttribute10": null,
        "extensionAttribute11": null,
        "extensionAttribute12": null,
        "extensionAttribute13": null,
        "extensionAttribute14": null,
        "extensionAttribute15": null
    }
}

Please share your thoughts.

2 Answers

I suppose you can't use the built-in powershell to do that. The onPremisesExtensionAttributes is a property just for the User object in Microsoft Graph, but the AzureAD or Az powershell both call Azure AD Graph API, the onPremisesExtensionAttributes property is not a property of the User in AAD Graph. Even if you have set that in the MS Graph, you could not get it with command like Get-AzureADUser.

If you want to use powershell to do that, your option is to call the MS Graph in powershell with Invoke-RestMethod, a sample here.

(Get-MgUser -UserId "[UserObjectID]").OnPremisesExtensionAttributes did return empty values.

After run: Select-MgProfile -Name "beta",

(Get-MgUser -UserId "[UserObjectID]").OnPremisesExtensionAttributes did return the values.

Related