Get-EntraSubscribedSku

訂閱了 Microsoft 服務 的 SKU。

語法

GetQuery (預設值)

Get-EntraSubscribedSku

    [-Property <String[]>]
    [<CommonParameters>]

GetById

Get-EntraSubscribedSku

    -SubscribedSkuId <String>
    [-Property <String[]>]
    [<CommonParameters>]

Description

指令Get-EntraSubscribedSku小程式會訂閱 Microsoft 服務 的 SKU。

在委託工作或學校帳號的情境中,當對其他使用者行動時,登入的使用者必須擁有支援的 Microsoft Entra 角色或具備必要權限的自訂角色。 以下最低權限角色支援此操作:

  • Dynamics 365 Business Central 管理員(標準屬性的唯讀存取)
  • 全球閱讀器
  • 目錄讀取者

範例

範例 1:取得訂閱的 SKU(SKU)

Connect-Entra -Scopes 'Organization.Read.All', 'LicenseAssignment.Read.All'
Get-EntraSubscribedSku
Id                                                                        AccountId                            AccountName   AppliesTo CapabilityStatus ConsumedUnits SkuId                                SkuPartNumber
--                                                                        ---------                            -----------   --------- ---------------- ------------- -----                                -------
aaaa0000-bb11-2222-33cc-444444dddddd 0000aaaa-11bb-cccc-dd22-eeeeee333333 M365x99297270 User      Enabled          20            aaaaaaaa-0b0b-1c1c-2d2d-333333333333 EMSP...
bbbb1111-cc22-3333-44dd-555555eeeeee 1111bbbb-22cc-dddd-ee33-ffffff444444 M365x99297270 User      Enabled          20            bbbbbbbb-1c1c-2d2d-3e3e-444444444444 ENTE...
cccc2222-dd33-4444-55ee-666666ffffff 2222cccc-33dd-eeee-ff44-aaaaaa555555 M365x99297270 User      Enabled          2             cccccccc-2d2d-3e3e-4f4f-555555555555 ENTE...

此範例示範如何取得已訂閱的 Microsoft 服務 SKU。

範例 2:由 SubscribedSkuId 取得訂閱的 SKU

Connect-Entra -Scopes 'Organization.Read.All', 'LicenseAssignment.Read.All'
Get-EntraSubscribedSku -SubscribedSkuId 'abcdefgh-1111-2222-bbbb-cccc33333333_dddddddd-4444-5555-eeee-666666666666'
Id                                                                        AccountId                            AccountName   AppliesTo CapabilityStatus ConsumedUnits SkuId                                SkuPartNumber
--                                                                        ---------                            -----------   --------- ---------------- ------------- -----                                -------
aaaa0000-bb11-2222-33cc-444444dddddd 0000aaaa-11bb-cccc-dd22-eeeeee333333 M365x99297270 User      Enabled          20            aaaaaaaa-0b0b-1c1c-2d2d-333333333333 EMSP...

此範例示範如何檢索指定訂閱的 SKU 至 Microsoft 服務。

  • -SubscribedSkuId 參數 指定 SKU(庫存管理單位)的 ID。

範例三:取得可用的授權方案

Connect-Entra -Scopes 'User.ReadWrite.All', 'Organization.Read.All', 'LicenseAssignment.Read.All'
Get-EntraSubscribedSku | Select-Object -Property Sku*, ConsumedUnits -ExpandProperty PrepaidUnits
Enabled              : 5
LockedOut            : 0
Suspended            : 0
Warning              : 0
AdditionalProperties :
SkuId                : efccb6f7-5641-4e0e-bd10-b4976e1bf68e
SkuPartNumber        : EMS
ConsumedUnits        : 3

此範例示範如何取得可用的授權方案。

範例 4:取得所有被指定授權的使用者

Connect-Entra -Scopes 'Organization.Read.All', 'LicenseAssignment.Read.All'
$sku = Get-EntraSubscribedSku | Where-Object { $_.SkuPartNumber -eq 'DEVELOPERPACK_E5' }
$skuId = $sku.SkuId
$usersWithDeveloperPackE5 = Get-EntraUser -All | Where-Object {
    $_.AssignedLicenses -and ($_.AssignedLicenses.SkuId -contains $skuId)
}
$usersWithDeveloperPackE5 | Select-Object Id, DisplayName, UserPrincipalName, AccountEnabled, UserType | Format-Table -AutoSize
Id                                   DisplayName     UserPrincipalName               AccountEnabled   UserType
--                                   -----------     -----------------               --------------   --------
cccccccc-2222-3333-4444-dddddddddddd  Angel Brown    AngelB@contoso.com              True             Member
dddddddd-3333-4444-5555-eeeeeeeeeeee  Avery Smith    AveryS@contoso.com              True             Member
eeeeeeee-4444-5555-6666-ffffffffffff  Sawyer Miller  SawyerM@contoso.com             True             Member

此範例示範如何取得所有被指派特定授權的使用者。

範例 5:取得使用者清單、他們被分配的授權條款及授權來源

Connect-Entra -Scopes 'Organization.Read.All', 'User.Read.All', 'Group.Read.All', 'LicenseAssignment.Read.All'

# Get all users with specified properties
$Users = Get-EntraUser -All -Property AssignedLicenses, LicenseAssignmentStates, DisplayName, UserPrincipalName, ObjectId

$SelectedUsers = $Users | Select-Object ObjectId, UserPrincipalName, DisplayName, AssignedLicenses -ExpandProperty LicenseAssignmentStates

# Group Name lookup
$GroupDisplayNames = @{}

# Sku Part Number lookup
$SkuPartNumbers = @{}

# Populate the hashtable with group display names and SKU part numbers
foreach ($User in $SelectedUsers) {
    $AssignedByGroup = $User.AssignedByGroup
    $SkuId = $User.SkuId

    try {
        # Check if the group display name is already in the hashtable
        if (-not $GroupDisplayNames.ContainsKey($AssignedByGroup)) {
            $Group = Get-EntraGroup -GroupId $AssignedByGroup
            $GroupDisplayNames[$AssignedByGroup] = $Group.DisplayName
        }

        $User | Add-Member -NotePropertyName 'GroupDisplayName' -NotePropertyValue $GroupDisplayNames[$AssignedByGroup]
    }
    catch {
        $User | Add-Member -NotePropertyName 'GroupDisplayName' -NotePropertyValue 'N/A (Direct Assignment)'
    }

    try {
        # Check if the SKU part number is already in the hashtable
        if (-not $SkuPartNumbers.ContainsKey($SkuId)) {
            $Sku = Get-EntraSubscribedSku | Where-Object { $_.SkuId -eq $SkuId } | Select-Object -ExpandProperty SkuPartNumber
            $SkuPartNumbers[$SkuId] = $Sku
        }

        $User | Add-Member -NotePropertyName 'SkuPartNumber' -NotePropertyValue $SkuPartNumbers[$SkuId]
    }
    catch {
        $User | Add-Member -NotePropertyName 'SkuPartNumber' -NotePropertyValue 'N/A'
    }
}

$SelectedUsers | Format-Table UserPrincipalName, DisplayName, AssignedByGroup, GroupDisplayName, SkuId, SkuPartNumber, State, Error -AutoSize
userPrincipalName       displayName       assignedByGroup                      GroupDisplayName    skuId                                SkuPartNumber  state  error
-----------------       -----------       ---------------                      ----------------    -----                                -------------  -----  -----
averyh@contoso.com      Avery Howard      cccccccc-2222-3333-4444-dddddddddddd Contoso Team        abcdefgh-1111-2222-bbbb-cccc33333333 ENTERPRISEPACK Active None
devont@contoso.com      Devon Torres      ffffffff-5555-6666-7777-aaaaaaaaaaaa Retail              abcdefgh-1111-2222-bbbb-cccc33333333 ENTERPRISEPACK Active None

此範例顯示使用者清單、授權及其來源,如直接指派或群組指派。

參數

-Property

指定要回傳的屬性。

參數屬性

類型:

System.String[]

預設值:None
支援萬用字元:False
不要顯示:False
別名:選取

參數集

(All)
Position:Named
必要:False
來自管線的值:False
來自管線按屬性名稱的值:False
來自剩餘引數的值:False

-SubscribedSkuId

SKU(庫存管理單位)的物件 ID。

參數屬性

類型:System.String
預設值:None
支援萬用字元:False
不要顯示:False
別名:ObjectId (物件識別碼)

參數集

GetById
Position:Named
必要:True
來自管線的值:True
來自管線按屬性名稱的值:True
來自剩餘引數的值:False

CommonParameters

此 Cmdlet 支援一般參數:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 如需詳細資訊,請參閱 about_CommonParameters。