2017-06-14 139 views
0

我登录到为创建测试而创建的Azure AD。我试图扩展属性添加到用户:通过Power Shell向Azure ActiveDirectory用户添加扩展属性

我第一次添加的扩展型到我的应用程序: 命令:

New-AzureADApplicationExtensionProperty -ObjectID 513aba62-4610-44ef-8be2-5a5e99a5e6bd -DataType "string" -Name "organisationId" 

结果:

extension_d939d34ab3f34f5dbb6e4e5c35e5787a_organisationId 

的ObjectId应用:513aba62-4610- 44ef-8be2-5a5e99a5e6bd

然后我检索扩展属性的ID: 命令:

Get-AzureADApplicationExtensionProperty -ObjectId 513aba62-4610-44ef-8be2-5a5e99a5e6bd 

现在我想在本扩展活动目录添加到我的第一个用户:

$User = Get-AzureADUser -Top 1 
Set-AzureADUserExtension -ObjectId $User.ObjectId -ExtensionName extension_d939d34ab3f34f5dbb6e4e5c35e5787a_organisationId -ExtensionValue "12345" 

错误:

Set-AzureADUserExtension : Error occurred while executing SetUser 
Code: Request_BadRequest Message: The following extension properties 
are not available for the given resource: 
extension_d939d34ab3f34f5dbb6e4e5c35e5787a_organisationId. RequestId: 
2cbeff0f-5b91-478a-8c64-586a4d23e4c5 DateTimeStamp: Wed, 14 Jun 2017 
13:49:02 GMT HttpStatusCode: BadRequest HttpStatusDescription: Bad 
Request HttpResponseStatus: Completed At line:2 char:1 
+ Set-AzureADUserExtension -ObjectId $User.ObjectId -ExtensionName exte ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (:) [Set-AzureADUserExtension], ApiException 
    + FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD.Graph.PowerShell.Custom.SetAzureADUserExtension 

我使用这些文档: https://docs.microsoft.com/en-us/powershell/module/azuread/set-azureaduserextension?view=azureadps-2.0

+0

你要足够长,它传播?像10-15分钟? – 4c74356b41

+0

我现在在2小时后试过了,还是一样的错误 –

回答

0

目前,我们无法使用PowerShell将扩展特性添加到Azure AD用户。 New-AzureADApplicationExtensionProperty创建扩展属性不适合用户,我们可以使用PowerShell命令Get-AzureADUser来检查它。

PS C:\Users\v-jianye> $d = get-azureaduser -ObjectId 65120ec5-3be1-4365-9d1c-b190414a830f 
PS C:\Users\v-jianye> $d.ExtensionProperty 

Key       Value 
---       ----- 
odata.metadata    https://graph.windows.net/5b47c786-9ca0-4347-9ec8-06590cad075f/$metadata#directoryObjects/Microsoft.DirectoryServices.User/@Element 
odata.type     Microsoft.DirectoryServices.User 
deletionTimestamp 
facsimileTelephoneNumber 
onPremisesDistinguishedName 

PS C:\Users\v-jianye> $c = get-azureaduser -ObjectId 9821a55c-c4c1-46dd-8471-5f99ee8e7c0d 
PS C:\Users\v-jianye> $c.ExtensionProperty 

Key                Value 
---                ----- 
odata.metadata             https://graph.windows.net/5b47c786-9ca0-4347-9ec8-06590cad075f/$metadata#directoryObjects/Microsoft.DirectoryServices.User/@Element 
odata.type              Microsoft.DirectoryServices.User 
deletionTimestamp 
facsimileTelephoneNumber 
onPremisesDistinguishedName 
[email protected]e Edm.DateTime 
extension_70e35fde0e05483aa8ace7c8c6d3fb93_whenCreated   12/6/2016 4:06:34 AM 

微软提供了两种自定义数据添加到使用扩展的资源,他们是开放扩展架构扩展
有关创建开放式扩展的详细信息,请参阅此link

0

我遇到了同样的问题。 对于我来说,为应用程序创建一个AzureAD服务主体似乎解决了这个问题。

# CREATE A NEW APP AND SERVICE PRINCIPAL 
$MyApp = (New-AzureADApplication -DisplayName "YourNewAppName" -IdentifierUris "https://dummy").ObjectId 
New-AzureADServicePrincipal -AppId (Get-AzureADApplication -SearchString "YourNewAppName").AppId 

# CREATE A NEW EXTENSION PROPERTY IN THE APP 
New-AzureADApplicationExtensionProperty -ObjectId $MyApp -Name "YourPropertyName" -DataType "String" -TargetObjects "User" 

# ADD THE NEW EXTENSION PROPERTY WITH A VALUE TO A USER 
$aadUser = Get-AzureADUser -ObjectId [email protected] 
Set-AzureADUserExtension -ObjectId $aadUser.ObjectId -ExtensionName "yourExtensionNameReturnedAbove" -ExtensionValue "YourPropertyValue" 

参见:MS PowerShell AzureAD Extension Attributes Sample

+1

虽然这个链接可能回答这个问题,但最好在这里包含答案的基本部分并提供参考链接。如果链接页面更改,则仅链接答案可能会失效。 - [来自评论](/ review/low-quality-posts/17893061) – Ploppy

+0

谢谢 - 我现在已经包含了代码。 – jrg999999