指派、更新、列出或移除使用者的自定義安全性屬性

Microsoft Entra 識別碼中的自訂安全性屬性 是商務特定屬性(索引鍵/值組),您可以定義並指派給 Microsoft Entra 物件。 例如,您可以指派自定義安全性屬性來篩選員工,或協助判斷誰可以存取資源。 本文說明如何指派、更新、列出或移除 Microsoft Entra 識別碼的自定義安全性屬性。

必要條件

若要為 Microsoft Entra 租使用者中的使用者指派或移除自訂安全性屬性,您需要:

重要

根據預設,全域 管理員 istrator 和其他系統管理員角色沒有讀取、定義或指派自定義安全性屬性的許可權。

將自訂安全性屬性指派給使用者

提示

本文中的步驟可能會根據您從開始的入口網站稍有不同。

  1. 以屬性指派 管理員 istrator 身分登入 Microsoft Entra 系統管理中心

  2. 請確定您已定義自訂安全性屬性。 如需詳細資訊,請參閱 在 Microsoft Entra ID 中新增或停用自定義安全性屬性定義。

  3. 流覽至 [身分>識別使用者>所有使用者]。

  4. 尋找並選取您要指派自定義安全性屬性的使用者。

  5. 在 [管理] 區段中,選取 [ 自定義安全性屬性]。

  6. 選取 [ 新增指派]。

  7. 在 [ 屬性集] 中,從清單中選取屬性集。

  8. 在 [ 屬性名稱] 中,從清單中選取自定義安全性屬性。

  9. 根據所選自定義安全性屬性的屬性,您可以輸入單一值、從預先定義的清單中選取值,或新增多個值。

    • 針對手繪多邊形、單一值自定義安全性屬性,請在 [ 指派的值] 方塊中輸入值
    • 針對預先定義的自定義安全性屬性值,請從 [ 指派的值] 清單中選取值
    • 針對多重值自定義安全性屬性,選取 [新增值 ] 以開啟 [屬性值 ] 窗格並新增您的值。 完成新增值時,請選取 [ 完成]。

    Screenshot showing assigning a custom security attribute to a user.

  10. 完成後,選取 [ 儲存 ] 將自定義安全性屬性指派給使用者。

更新使用者的自定義安全性屬性指派值

  1. 以屬性指派 管理員 istrator 身分登入 Microsoft Entra 系統管理中心。

  2. 流覽至 [身分>識別使用者>所有使用者]。

  3. 尋找並選取具有您要更新之自定義安全性屬性指派值的使用者。

  4. 在 [管理] 區段中,選取 [ 自定義安全性屬性]。

  5. 尋找您想要更新的自訂安全性屬性指派值。

    將自定義安全性屬性指派給用戶之後,您就只能變更自定義安全性屬性的值。 您無法變更自定義安全性屬性的其他屬性,例如屬性集或屬性名稱。

  6. 視所選自定義安全性屬性的屬性而定,您可以更新單一值、從預先定義的清單中選取值,或更新多個值。

  7. 完成後,請選取儲存

根據自訂安全性屬性指派篩選使用者

您可以在[所有使用者] 頁面上篩選指派給使用者的自訂安全性屬性清單。

  1. 以屬性指派讀取器身分登入 Microsoft Entra 系統管理中心

  2. 流覽至 [身分>識別使用者>所有使用者]。

  3. 選取 [新增篩選 ] 以開啟 [新增篩選] 窗格。

  4. 選取 [自定義安全性屬性]。

  5. 選取您的屬性集和屬性名稱。

  6. 針對 [運算符],您可以選取等於 (==)、不等於 (!=),或 開頭為 。

  7. 針對 [ ],輸入或選取值。

    Screenshot showing a custom security attribute filter for users.

  8. 若要套用篩選,請選取 [ 套用]。

從使用者移除自定義安全性屬性指派

  1. 以屬性指派 管理員 istrator 身分登入 Microsoft Entra 系統管理中心。

  2. 流覽至 [身分>識別使用者>所有使用者]。

  3. 尋找並選取具有您想要移除之自定義安全性屬性指派的使用者。

  4. 在 [管理] 區段中,選取 [ 自定義安全性屬性]。

  5. 在您想要移除的所有自訂安全性屬性指派旁邊新增複選標記。

  6. 選取 [ 移除指派]。

PowerShell 或 Microsoft Graph API

若要管理 Microsoft Entra 組織中使用者的自定義安全性屬性指派,您可以使用 PowerShell 或 Microsoft Graph API。 下列範例可用來管理指派。

將具有字串值的自定義安全性屬性指派給使用者

下列範例會將具有字串值的自定義安全性屬性指派給使用者。

  • 屬性集: Engineering
  • 屬性: ProjectDate
  • 屬性數據類型:字串
  • 屬性值: "2024-11-15"

Update-MgUser

$customSecurityAttributes = @{
    "Engineering" = @{
        "@odata.type" = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue"
        "ProjectDate" = "2024-11-15"
    }
}
Update-MgUser -UserId $userId -CustomSecurityAttributes $customSecurityAttributes

將具有多字串值的自定義安全性屬性指派給使用者

下列範例會將具有多字串值的自定義安全性屬性指派給使用者。

  • 屬性集: Engineering
  • 屬性: Project
  • 屬性數據類型:字串集合
  • 屬性值: ["Baker","Cascade"]

Update-MgUser

$customSecurityAttributes = @{
    "Engineering" = @{
        "@odata.type" = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue"
        "Project@odata.type" = "#Collection(String)"
        "Project" = @("Baker","Cascade")
    }
}
Update-MgUser -UserId $userId -CustomSecurityAttributes $customSecurityAttributes

將具有整數值的自定義安全性屬性指派給使用者

下列範例會將具有整數值的自定義安全性屬性指派給使用者。

  • 屬性集: Engineering
  • 屬性: NumVendors
  • 屬性數據類型:整數
  • 屬性值: 4

Update-MgUser

$customSecurityAttributes = @{
    "Engineering" = @{
        "@odata.type" = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue"
        "NumVendors@odata.type" = "#Int32"
        "NumVendors" = 4
    }
}
Update-MgUser -UserId $userId -CustomSecurityAttributes $customSecurityAttributes

將具有多整數值的自定義安全性屬性指派給使用者

下列範例會將具有多整數值的自定義安全性屬性指派給使用者。

  • 屬性集: Engineering
  • 屬性: CostCenter
  • 屬性數據類型:整數集合
  • 屬性值: [1001,1003]

Update-MgUser

$customSecurityAttributes = @{
    "Engineering" = @{
        "@odata.type" = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue"
        "CostCenter@odata.type" = "#Collection(Int32)"
        "CostCenter" = @(1001,1003)
    }
}
Update-MgUser -UserId $userId -CustomSecurityAttributes $customSecurityAttributes

將具有布爾值之自定義安全性屬性指派給使用者

下列範例會將具有布爾值之自定義安全性屬性指派給使用者。

  • 屬性集: Engineering
  • 屬性: Certification
  • 屬性數據類型:布爾值
  • 屬性值: true

Update-MgUser

$customSecurityAttributes = @{
    "Engineering" = @{
        "@odata.type" = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue"
        "Certification" = $true
    }
}
Update-MgUser -UserId $userId -CustomSecurityAttributes $customSecurityAttributes

使用使用者的整數值更新自定義安全性屬性指派

下列範例會使用使用者的整數值來更新自定義安全性屬性指派。

  • 屬性集: Engineering
  • 屬性: NumVendors
  • 屬性數據類型:整數
  • 屬性值: 8

Update-MgUser

$customSecurityAttributes = @{
    "Engineering" = @{
        "@odata.type" = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue"
        "NumVendors@odata.type" = "#Int32"
        "NumVendors" = 8
    }
}
Update-MgUser -UserId $userId -CustomSecurityAttributes $customSecurityAttributes

使用使用者的布爾值更新自定義安全性屬性指派

下列範例會使用使用者的布爾值來更新自定義安全性屬性指派。

  • 屬性集: Engineering
  • 屬性: Certification
  • 屬性數據類型:布爾值
  • 屬性值: false

Update-MgUser

$customSecurityAttributes = @{
    "Engineering" = @{
        "@odata.type" = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue"
        "Certification" = $false
    }
}
Update-MgUser -UserId $userId -CustomSecurityAttributes $customSecurityAttributes

使用使用者的多重字串值更新自定義安全性屬性指派

下列範例會使用使用者的多重字串值來更新自定義安全性屬性指派。

  • 屬性集: Engineering
  • 屬性: Project
  • 屬性數據類型:字串集合
  • 屬性值: ("Alpine","Baker")

Update-MgUser

$customSecurityAttributes = @{
    "Engineering" = @{
        "@odata.type" = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue"
        "Project@odata.type" = "#Collection(String)"
        "Project" = @("Alpine","Baker")
    }
}
Update-MgUser -UserId $userId -CustomSecurityAttributes $customSecurityAttributes

取得使用者的自定義安全性屬性指派

下列範例會取得使用者的自定義安全性屬性指派。

Get-MgUser

$userAttributes = Get-MgUser -UserId $userId -Property "customSecurityAttributes"
$userAttributes.CustomSecurityAttributes.AdditionalProperties | Format-List
$userAttributes.CustomSecurityAttributes.AdditionalProperties.Engineering
$userAttributes.CustomSecurityAttributes.AdditionalProperties.Marketing
Key   : Engineering
Value : {[@odata.type, #microsoft.graph.customSecurityAttributeValue], [Project@odata.type, #Collection(String)], [Project, System.Object[]],
        [ProjectDate, 2024-11-15]…}

Key   : Marketing
Value : {[@odata.type, #microsoft.graph.customSecurityAttributeValue], [EmployeeId, GS45897]}


Key                   Value
---                   -----
@odata.type           #microsoft.graph.customSecurityAttributeValue
Project@odata.type    #Collection(String)
Project               {Baker, Alpine}
ProjectDate           2024-11-15
NumVendors            8
CostCenter@odata.type #Collection(Int32)
CostCenter            {1001, 1003}
Certification         False


Key         Value
---         -----
@odata.type #microsoft.graph.customSecurityAttributeValue
EmployeeId  KX45897

如果沒有指派給使用者的自定義安全性屬性,或呼叫主體沒有存取權,回應將會是空的。

列出具有等於值之自定義安全性屬性指派的所有使用者

下列範例會列出具有等於值之自定義安全性屬性指派的所有使用者。 它會擷取具有名為 AppCountry 之自訂安全性屬性的使用者,其值等於 Canada。 篩選值會區分大小寫。 您必須在要求或標頭中新增 ConsistencyLevel=eventual 。 您也必須包含 $count=true ,以確保要求已正確路由傳送。

  • 屬性集: Marketing
  • 屬性: AppCountry
  • 篩選:AppCountry eq 'Canada'

Get-MgUser

$userAttributes = Get-MgUser -CountVariable CountVar -Property "id,displayName,customSecurityAttributes" -Filter "customSecurityAttributes/Marketing/AppCountry eq 'Canada'" -ConsistencyLevel eventual
$userAttributes | select Id,DisplayName,CustomSecurityAttributes
$userAttributes.CustomSecurityAttributes.AdditionalProperties | Format-List
Id                                   DisplayName CustomSecurityAttributes
--                                   ----------- ------------------------
4b4e8090-e9ba-4bdc-b2f0-67c3c7c59489 Jiya        Microsoft.Graph.PowerShell.Models.MicrosoftGraphCustomSecurityAttributeValue
efdf3082-64ae-495f-b051-855e2d8df969 Jana        Microsoft.Graph.PowerShell.Models.MicrosoftGraphCustomSecurityAttributeValue

Key   : Engineering
Value : {[@odata.type, #microsoft.graph.customSecurityAttributeValue], [Datacenter@odata.type, #Collection(String)], [Datacenter, System.Object[]]}

Key   : Marketing
Value : {[@odata.type, #microsoft.graph.customSecurityAttributeValue], [AppCountry@odata.type, #Collection(String)], [AppCountry, System.Object[]],
        [EmployeeId, KX19476]}

Key   : Marketing
Value : {[@odata.type, #microsoft.graph.customSecurityAttributeValue], [AppCountry@odata.type, #Collection(String)], [AppCountry, System.Object[]],
        [EmployeeId, GS46982]}

列出所有使用者,其中包含以值開頭的自定義安全性屬性指派

下列範例會列出所有使用者,其中包含以 值開頭的自定義安全性屬性指派。 它會擷取具有以 開頭 EmployeeId 之值的 GS自定義安全性屬性的使用者。 篩選值會區分大小寫。 您必須在要求或標頭中新增 ConsistencyLevel=eventual 。 您也必須包含 $count=true ,以確保要求已正確路由傳送。

  • 屬性集: Marketing
  • 屬性: EmployeeId
  • 篩選:EmployeeId startsWith 'GS'

Get-MgUser

$userAttributes = Get-MgUser -CountVariable CountVar -Property "id,displayName,customSecurityAttributes" -Filter "startsWith(customSecurityAttributes/Marketing/EmployeeId,'GS')" -ConsistencyLevel eventual
$userAttributes | select Id,DisplayName,CustomSecurityAttributes
$userAttributes.CustomSecurityAttributes.AdditionalProperties | Format-List
Id                                   DisplayName CustomSecurityAttributes
--                                   ----------- ------------------------
02d52406-be75-411b-b02f-29d7f38dcf62 Chandra     Microsoft.Graph.PowerShell.Models.MicrosoftGraphCustomSecurityAttributeValue
efdf3082-64ae-495f-b051-855e2d8df969 Jana        Microsoft.Graph.PowerShell.Models.MicrosoftGraphCustomSecurityAttributeValue
d5a1c025-2d79-4ad3-9217-91ac3a4ed8b8 Joe         Microsoft.Graph.PowerShell.Models.MicrosoftGraphCustomSecurityAttributeValue

Key   : Marketing
Value : {[@odata.type, #microsoft.graph.customSecurityAttributeValue], [EmployeeId, GS36348]}

Key   : Marketing
Value : {[@odata.type, #microsoft.graph.customSecurityAttributeValue], [AppCountry@odata.type, #Collection(String)], [AppCountry, System.Object[]],
        [EmployeeId, GS46982]}

Key   : Engineering
Value : {[@odata.type, #microsoft.graph.customSecurityAttributeValue], [Project@odata.type, #Collection(String)], [Project, System.Object[]],
        [ProjectDate, 2024-11-15]…}

Key   : Marketing
Value : {[@odata.type, #microsoft.graph.customSecurityAttributeValue], [EmployeeId, GS45897]}

列出具有不等於值之自定義安全性屬性指派的所有使用者

下列範例會列出具有不等於值的自定義安全性屬性指派的所有使用者。 它會擷取具有名為 AppCountry 且值不等於 Canada之自定義安全性屬性的使用者。 篩選值會區分大小寫。 您必須在要求或標頭中新增 ConsistencyLevel=eventual 。 您也必須包含 $count=true ,以確保要求已正確路由傳送。

  • 屬性集: Marketing
  • 屬性: AppCountry
  • 篩選:AppCountry ne 'Canada'

Get-MgUser

$userAttributes = Get-MgUser -CountVariable CountVar -Property "id,displayName,customSecurityAttributes" -Filter "customSecurityAttributes/Marketing/AppCountry ne 'Canada'" -ConsistencyLevel eventual
$userAttributes | select Id,DisplayName,CustomSecurityAttributes
Id                                   DisplayName              CustomSecurityAttributes
--                                   -----------              ------------------------
02d52406-be75-411b-b02f-29d7f38dcf62 Chandra                  Microsoft.Graph.PowerShell.Models.MicrosoftGraphCustomSecurityAttributeValue
eaea4971-7764-4498-9aeb-776496812e75 Isabella                 Microsoft.Graph.PowerShell.Models.MicrosoftGraphCustomSecurityAttributeValue
d937580c-692c-451f-a507-6758d3bdf353 Alain                    Microsoft.Graph.PowerShell.Models.MicrosoftGraphCustomSecurityAttributeValue
d5a1c025-2d79-4ad3-9217-91ac3a4ed8b8 Joe                      Microsoft.Graph.PowerShell.Models.MicrosoftGraphCustomSecurityAttributeValue
23ad8721-f46c-421a-9785-33b0ef474198 Dara                     Microsoft.Graph.PowerShell.Models.MicrosoftGraphCustomSecurityAttributeValue

從使用者移除單一值自定義安全性屬性指派

下列範例會藉由將值設定為 null,從使用者移除單一值自定義安全性屬性指派。

  • 屬性集: Engineering
  • 屬性: ProjectDate
  • 屬性值: null

Invoke-MgGraphRequest

$params = @{
    "customSecurityAttributes" = @{
        "Engineering" = @{
            "@odata.type" = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue"
            "ProjectDate" = $null
        }
    }
}
Invoke-MgGraphRequest -Method PATCH -Uri "https://graph.microsoft.com/v1.0/users/$userId" -Body $params

從使用者移除多重值自定義安全性屬性指派

下列範例會藉由將值設定為空白集合,從使用者移除多重值自定義安全性屬性指派。

  • 屬性集: Engineering
  • 屬性: Project
  • 屬性值: []

Update-MgUser

$customSecurityAttributes = @{
    "Engineering" = @{
        "@odata.type" = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue"
        "Project" = @()
    }
}
Update-MgUser -UserId $userId -CustomSecurityAttributes $customSecurityAttributes

常見問題集

用戶支援的自定義安全性屬性指派在哪裡?

Microsoft Entra 系統管理中心、PowerShell 和 Microsoft Graph API 支援使用者的自定義安全性屬性指派。 我的應用程式 或 Microsoft 365 系統管理中心 不支援自定義安全性屬性指派。

神秘 可以檢視指派給使用者的自訂安全性屬性嗎?

只有已在租用戶範圍指派屬性指派 管理員 istrator 或屬性指派讀取器角色的使用者,才能檢視指派給租使用者中任何使用者的自定義安全性屬性。 使用者無法檢視指派給自己配置檔或其他使用者的自訂安全性屬性。 無論租用戶上設定的來賓許可權為何,來賓都無法檢視自定義安全性屬性。

我需要建立應用程式以新增自定義安全性屬性指派嗎?

否,不需要應用程式,即可將自定義安全性屬性指派給用戶物件。

為什麼我持續收到嘗試儲存自訂安全性屬性指派的錯誤?

您沒有許可權將自訂安全性屬性指派給使用者。 請確定您已獲指派屬性指派管理員istrator 角色。

我可以將自訂安全性屬性指派給來賓嗎?

是,您可以將自訂安全性屬性指派給租使用者中的成員或來賓。

我可以將自訂安全性屬性指派給目錄同步處理的使用者嗎?

是,可以從內部部署的 Active Directory指派目錄同步使用者自訂安全性屬性。

自訂安全性屬性指派是否可用於動態成員資格規則?

否,不支援指派給使用者的自訂安全性屬性來設定動態成員資格規則。

自訂安全性屬性是否與 B2C 租使用者中的自訂屬性相同?

否,B2C 租使用者不支援自訂安全性屬性,且與 B2C 功能無關。

下一步