在 Microsoft Entra ID 中新增或停用自定義安全性屬性定義

Microsoft Entra ID 中的自訂安全性屬性 是商務特定屬性(索引鍵/值組),您可以定義並指派給 Microsoft Entra 物件。 本文說明如何新增、編輯或停用自定義安全性屬性定義。

必要條件

若要新增或停用自定義安全性屬性定義,您必須具備:

重要

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

新增屬性集

提示

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

屬性集是相關屬性的集合。 所有自訂安全性屬性都必須是屬性集的一部分。 無法重新命名或刪除屬性集。

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

  2. 流覽至 [保護>自定義安全性屬性]。

  3. 按兩下 [新增屬性集 ] 以新增屬性集。

    如果停用 [新增屬性集],請確定您已獲指派屬性定義 管理員 istrator 角色。 如需詳細資訊,請參閱 針對自定義安全性屬性進行疑難解答。

  4. 輸入名稱、描述和屬性數目上限。

    屬性集名稱可以是 32 個字元,不含空格或特殊字元。 指定名稱之後,就無法重新命名它。 如需詳細資訊,請參閱 限制和條件約束

    Screenshot of New attribute set pane in Microsoft Entra admin center.

  5. 完成後,按一下 [新增]

    新的屬性集會出現在屬性集清單中。

新增自訂安全性屬性定義

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

  2. 流覽至 [保護>自定義安全性屬性]。

  3. 在 [自定義安全性屬性] 頁面上,尋找現有的屬性集,或按兩下 [ 新增屬性集 ] 以新增屬性集。

    所有自訂安全性屬性定義都必須是屬性集的一部分。

  4. 按兩下以開啟選取的屬性集。

  5. 按兩下 [新增屬性 ],將新的自定義安全性屬性新增至屬性集。

    Screenshot of New attribute pane in Microsoft Entra admin center.

  6. 在 [ 屬性名稱] 方塊中,輸入自定義安全性屬性名稱。

    自定義安全性屬性名稱可以是 32 個字元,沒有空格或特殊字元。 指定名稱之後,就無法重新命名它。 如需詳細資訊,請參閱 限制和條件約束

  7. 在 [ 描述] 方塊中,輸入選擇性描述。

    描述長度可以是 128 個字元。 如有必要,您可以稍後變更描述。

  8. 從 [ 資料類型 ] 清單中,選取自定義安全性屬性的數據類型。

    資料類型 描述
    布林值 布爾值,可以是 true、True、false 或 False。
    整數 32 位元整數。
    String 長度為 X 個字元的字串。
  9. 針對 [允許指派多個值],選取 [是] 或 []。

    選取 [ ] 以允許將多個值指派給這個自定義安全性屬性。 選取 [否 ],只允許將單一值指派給這個自定義安全性屬性。

  10. 針對 [僅允許指派預先定義的值],選取 [是] 或 []。

    選取 [ ],要求從預先定義的值清單中指派此自定義安全性屬性。 選取 [否 ] 可允許指派此自定義安全性屬性的使用者定義值或可能預先定義的值。

  11. 如果 [只允許指派 預先定義的值] 是 [是],請按兩下 [ 新增值 ] 以新增預先定義的值。

    使用中的值可用於指派給物件。 未使用中的值已定義,但尚未可供指派使用。

    Screenshot of New attribute pane with Add predefined value pane in Microsoft Entra admin center.

  12. 完成時,按一下 [儲存]。

    新的自訂安全性屬性會出現在自定義安全性屬性清單中。

  13. 如果您想要包含預先定義的值,請遵循下一節中的步驟。

編輯自定義安全性屬性定義

新增自訂安全性屬性定義之後,您可以稍後編輯一些屬性。 某些屬性是不可變的,無法變更。

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

  2. 流覽至 [保護>自定義安全性屬性]。

  3. 按兩下包含您要編輯之自訂安全性屬性的屬性集。

  4. 在自定義安全性屬性清單中,按下您要編輯之自定義安全性屬性的省略號,然後選取 [編輯屬性]。

  5. 編輯已啟用的屬性。

  6. 如果 [只允許指派 預先定義的值] 是 [是],請按兩下 [ 新增值 ] 以新增預先定義的值。 按兩下現有的預先定義值來變更 [作用中 嗎? ] 設定。

    Screenshot of Add predefined value pane in Microsoft Entra admin center.

停用自定義安全性屬性定義

新增自定義安全性屬性定義之後,就無法將其刪除。 不過,您可以停用自定義安全性屬性定義。

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

  2. 流覽至 [保護>自定義安全性屬性]。

  3. 按兩下包含您要停用之自訂安全性屬性的屬性集。

  4. 在自訂安全性屬性清單中,新增您要停用之自定義安全性屬性旁的複選標記。

  5. 按兩下 [ 停用屬性]。

  6. 在出現的 [停用屬性] 對話框中,按兩下 [ ]。

    自訂安全性屬性已停用,並移至 [已停用的屬性] 清單。

PowerShell 或 Microsoft Graph API

若要管理 Microsoft Entra 組織中的自訂安全性屬性定義,您也可以使用 PowerShell 或 Microsoft Graph API。 下列範例會管理屬性集和自定義安全性屬性定義。

取得所有屬性集

下列範例會取得所有屬性集。

Get-MgDirectoryAttributeSet

Get-MgDirectoryAttributeSet | Format-List
Description          : Attributes for engineering team
Id                   : Engineering
MaxAttributesPerSet  : 25
AdditionalProperties : {}

Description          : Attributes for marketing team
Id                   : Marketing
MaxAttributesPerSet  : 25
AdditionalProperties : {}

取得最上層屬性集

下列範例會取得頂端屬性集。

Get-MgDirectoryAttributeSet

Get-MgDirectoryAttributeSet -Top 10

依序取得屬性集

下列範例會依序取得屬性集。

Get-MgDirectoryAttributeSet

Get-MgDirectoryAttributeSet -Sort "Id"

取得屬性集

下列範例會取得屬性集。

  • 屬性集: Engineering

Get-MgDirectoryAttributeSet

Get-MgDirectoryAttributeSet -AttributeSetId "Engineering" | Format-List
Description          : Attributes for engineering team
Id                   : Engineering
MaxAttributesPerSet  : 25
AdditionalProperties : {[@odata.context, https://graph.microsoft.com/v1.0/$metadata#directory/attributeSets/$entity]}

新增屬性集

下列範例會新增屬性集。

  • 屬性集: Engineering

New-MgDirectoryAttributeSet

$params = @{
    Id = "Engineering"
    Description = "Attributes for engineering team"
    MaxAttributesPerSet = 25
}
New-MgDirectoryAttributeSet -BodyParameter $params
Id          Description                     MaxAttributesPerSet
--          -----------                     -------------------
Engineering Attributes for engineering team 25

更新屬性集

下列範例會更新屬性集。

  • 屬性集: Engineering

Update-MgDirectoryAttributeSet

$params = @{
    description = "Attributes for engineering team"
    maxAttributesPerSet = 20
}
Update-MgDirectoryAttributeSet -AttributeSetId "Engineering" -BodyParameter $params

取得所有自定義安全性屬性定義

下列範例會取得所有自定義安全性屬性定義。

Get-MgDirectoryCustomSecurityAttributeDefinition

Get-MgDirectoryCustomSecurityAttributeDefinition | Format-List
AllowedValues           :
AttributeSet            : Engineering
Description             : Target completion date
Id                      : Engineering_ProjectDate
IsCollection            : False
IsSearchable            : True
Name                    : ProjectDate
Status                  : Available
Type                    : String
UsePreDefinedValuesOnly : False
AdditionalProperties    : {}

AllowedValues           :
AttributeSet            : Engineering
Description             : Active projects for user
Id                      : Engineering_Project
IsCollection            : True
IsSearchable            : True
Name                    : Project
Status                  : Available
Type                    : String
UsePreDefinedValuesOnly : True
AdditionalProperties    : {}

AllowedValues           :
AttributeSet            : Marketing
Description             : Country where is application is used
Id                      : Marketing_AppCountry
IsCollection            : True
IsSearchable            : True
Name                    : AppCountry
Status                  : Available
Type                    : String
UsePreDefinedValuesOnly : True
AdditionalProperties    : {}

篩選自定義安全性屬性定義

下列範例會篩選自定義安全性屬性定義。

  • 篩選:屬性名稱 eq 'Project' 和狀態 eq 'Available'

Get-MgDirectoryCustomSecurityAttributeDefinition

Get-MgDirectoryCustomSecurityAttributeDefinition -Filter "name eq 'Project' and status eq 'Available'" | Format-List
AllowedValues           :
AttributeSet            : Engineering
Description             : Active projects for user
Id                      : Engineering_Project
IsCollection            : True
IsSearchable            : True
Name                    : Project
Status                  : Available
Type                    : String
UsePreDefinedValuesOnly : True
AdditionalProperties    : {}
  • 篩選:屬性集 eq 'Engineering' 和 status eq 'Available' 和數據類型 eq 'String'

Get-MgDirectoryCustomSecurityAttributeDefinition

Get-MgDirectoryCustomSecurityAttributeDefinition -Filter "attributeSet eq 'Engineering' and status eq 'Available' and type eq 'String'" | Format-List
AllowedValues           :
AttributeSet            : Engineering
Description             : Target completion date
Id                      : Engineering_ProjectDate
IsCollection            : False
IsSearchable            : True
Name                    : ProjectDate
Status                  : Available
Type                    : String
UsePreDefinedValuesOnly : False
AdditionalProperties    : {}

AllowedValues           :
AttributeSet            : Engineering
Description             : Active projects for user
Id                      : Engineering_Project
IsCollection            : True
IsSearchable            : True
Name                    : Project
Status                  : Available
Type                    : String
UsePreDefinedValuesOnly : True
AdditionalProperties    : {}

取得自訂安全性屬性定義

下列範例會取得自定義安全性屬性定義。

  • 屬性集: Engineering
  • 屬性: ProjectDate

Get-MgDirectoryCustomSecurityAttributeDefinition

Get-MgDirectoryCustomSecurityAttributeDefinition -CustomSecurityAttributeDefinitionId "Engineering_ProjectDate" | Format-List
AllowedValues           :
AttributeSet            : Engineering
Description             : Target completion date
Id                      : Engineering_ProjectDate
IsCollection            : False
IsSearchable            : True
Name                    : ProjectDate
Status                  : Available
Type                    : String
UsePreDefinedValuesOnly : False
AdditionalProperties    : {[@odata.context, https://graph.microsoft.com/v1.0/$metadata#directory/customSecurityAttributeDefinitions/$entity]}

新增自訂安全性屬性定義

下列範例會新增新的自定義安全性屬性定義。

  • 屬性集: Engineering
  • 屬性: ProjectDate
  • 屬性數據類型:字串

New-MgDirectoryCustomSecurityAttributeDefinition

$params = @{
    attributeSet = "Engineering"
    description = "Target completion date"
    isCollection = $false
    isSearchable = $true
    name = "ProjectDate"
    status = "Available"
    type = "String"
    usePreDefinedValuesOnly = $false
}
New-MgDirectoryCustomSecurityAttributeDefinition -BodyParameter $params | Format-List
AllowedValues           :
AttributeSet            : Engineering
Description             : Target completion date
Id                      : Engineering_ProjectDate
IsCollection            : False
IsSearchable            : True
Name                    : ProjectDate
Status                  : Available
Type                    : String
UsePreDefinedValuesOnly : False
AdditionalProperties    : {[@odata.context, https://graph.microsoft.com/v1.0/$metadata#directory/customSecurityAttributeDefinitions/$entity]}

新增支援多個預先定義值的自定義安全性屬性定義

下列範例會新增支援多個預先定義值的新自定義安全性屬性定義。

  • 屬性集: Engineering
  • 屬性: Project
  • 屬性數據類型:字串集合

New-MgDirectoryCustomSecurityAttributeDefinition

$params = @{
    attributeSet = "Engineering"
    description = "Active projects for user"
    isCollection = $true
    isSearchable = $true
    name = "Project"
    status = "Available"
    type = "String"
    usePreDefinedValuesOnly = $true
}
New-MgDirectoryCustomSecurityAttributeDefinition -BodyParameter $params | Format-List
AllowedValues           :
AttributeSet            : Engineering
Description             : Active projects for user
Id                      : Engineering_Project
IsCollection            : True
IsSearchable            : True
Name                    : Project
Status                  : Available
Type                    : String
UsePreDefinedValuesOnly : True
AdditionalProperties    : {[@odata.context, https://graph.microsoft.com/v1.0/$metadata#directory/customSecurityAttributeDefinitions/$entity]}

新增具有預先定義值清單的自定義安全性屬性定義

下列範例會新增具有預先定義值清單的新自定義安全性屬性定義。

  • 屬性集: Engineering
  • 屬性: Project
  • 屬性數據類型:字串集合
  • 預先定義的值:Alpine、、 BakerCascade

New-MgDirectoryCustomSecurityAttributeDefinition

$params = @{
    attributeSet = "Engineering"
    description = "Active projects for user"
    isCollection = $true
    isSearchable = $true
    name = "Project"
    status = "Available"
    type = "String"
    usePreDefinedValuesOnly = $true
    allowedValues = @(
        @{
            id = "Alpine"
            isActive = $true
        }
        @{
            id = "Baker"
            isActive = $true
        }
        @{
            id = "Cascade"
            isActive = $true
        }
    )
}
New-MgDirectoryCustomSecurityAttributeDefinition -BodyParameter $params | Format-List
AllowedValues           :
AttributeSet            : Engineering
Description             : Active projects for user
Id                      : Engineering_Project
IsCollection            : True
IsSearchable            : True
Name                    : Project
Status                  : Available
Type                    : String
UsePreDefinedValuesOnly : True
AdditionalProperties    : {[@odata.context, https://graph.microsoft.com/v1.0/$metadata#directory/customSecurityAttributeDefinitions/$entity]}

更新自定義安全性屬性定義

下列範例會更新自定義安全性屬性定義。

  • 屬性集: Engineering
  • 屬性: ProjectDate

Update-MgDirectoryCustomSecurityAttributeDefinition

$params = @{
    description = "Target completion date (YYYY/MM/DD)"
}
Update-MgDirectoryCustomSecurityAttributeDefinition -CustomSecurityAttributeDefinitionId "Engineering_ProjectDate" -BodyParameter $params

更新自訂安全性屬性定義的預先定義值

下列範例會更新自定義安全性屬性定義的預先定義值。

  • 屬性集: Engineering
  • 屬性: Project
  • 屬性數據類型:字串集合
  • 更新預先定義的值: Baker
  • 新的預先定義值: Skagit

Invoke-MgGraphRequest

注意

針對此要求,您必須新增 OData-Version 標頭,並將值 4.01指派給它。

$params = @{
    "allowedValues@delta" = @(
        @{
            id = "Baker"
            isActive = $false
        }
        @{
            id = "Skagit"
            isActive = $true
        }
    )
}
$header = @{
    "OData-Version" = 4.01
}
Invoke-MgGraphRequest -Method PATCH -Uri "https://graph.microsoft.com/v1.0/directory/customSecurityAttributeDefinitions/Engineering_Project5" -Headers $header -Body $params

停用自定義安全性屬性定義

下列範例會停用自定義安全性屬性定義。

  • 屬性集: Engineering
  • 屬性: Project

Update-MgDirectoryCustomSecurityAttributeDefinition

$params = @{
    status = "Deprecated"
}
Update-MgDirectoryCustomSecurityAttributeDefinition -CustomSecurityAttributeDefinitionId "Engineering_ProjectDate" -BodyParameter $params

取得所有預先定義的值

下列範例會取得自定義安全性屬性定義的所有預先定義值。

  • 屬性集: Engineering
  • 屬性: Project

Get-MgDirectoryCustomSecurityAttributeDefinitionAllowedValue

Get-MgDirectoryCustomSecurityAttributeDefinitionAllowedValue -CustomSecurityAttributeDefinitionId "Engineering_Project" | Format-List
Id                   : Skagit
IsActive             : True
AdditionalProperties : {}

Id                   : Baker
IsActive             : False
AdditionalProperties : {}

Id                   : Cascade
IsActive             : True
AdditionalProperties : {}

Id                   : Alpine
IsActive             : True
AdditionalProperties : {}

取得預先定義的值

下列範例會取得自定義安全性屬性定義的預先定義值。

  • 屬性集: Engineering
  • 屬性: Project
  • 預先定義的值: Alpine

Get-MgDirectoryCustomSecurityAttributeDefinitionAllowedValue

Get-MgDirectoryCustomSecurityAttributeDefinitionAllowedValue -CustomSecurityAttributeDefinitionId "Engineering_Project" -AllowedValueId "Alpine" | Format-List
Id                   : Alpine
IsActive             : True
AdditionalProperties : {[@odata.context, https://graph.microsoft.com/v1.0/$metadata#directory/customSecurityAttributeDefinitions('Engineering_Project')/al
                       lowedValues/$entity]}

新增預先定義的值

下列範例會新增自定義安全性屬性定義的預先定義值。

您可以為已 usePreDefinedValuesOnly 設定為 true的自訂安全性屬性新增預先定義的值。

  • 屬性集: Engineering
  • 屬性: Project
  • 預先定義的值: Alpine

New-MgDirectoryCustomSecurityAttributeDefinitionAllowedValue

$params = @{
    id = "Alpine"
    isActive = $true
}
New-MgDirectoryCustomSecurityAttributeDefinitionAllowedValue -CustomSecurityAttributeDefinitionId "Engineering_Project" -BodyParameter $params | Format-List
Id                   : Alpine
IsActive             : True
AdditionalProperties : {[@odata.context, https://graph.microsoft.com/v1.0/$metadata#directory/customSecurityAttributeDefinitions('Engineering_Project')/al
                       lowedValues/$entity]}

停用預先定義的值

下列範例會停用自定義安全性屬性定義的預先定義值。

  • 屬性集: Engineering
  • 屬性: Project
  • 預先定義的值: Alpine

Update-MgDirectoryCustomSecurityAttributeDefinitionAllowedValue

$params = @{
    isActive = $false
}
Update-MgDirectoryCustomSecurityAttributeDefinitionAllowedValue -CustomSecurityAttributeDefinitionId "Engineering_Project" -AllowedValueId "Alpine" -BodyParameter $params

常見問題集

您可以刪除自訂安全性屬性定義嗎?

否,您無法刪除自定義安全性屬性定義。 您只能 停用自訂安全性屬性定義。 停用自定義安全性屬性之後,就無法再將它套用至 Microsoft Entra 物件。 停用之自定義安全性屬性定義的自定義安全性屬性指派不會自動移除。 停用的自定義安全性屬性數目沒有限制。 每個租使用者可以有 500 個作用中的自訂安全性屬性定義,每個自定義安全性屬性定義允許 100 個預先定義值。

下一步