使用 PowerShell 查看 Microsoft 365 帐户许可证和服务详细信息

此文章适用于 Microsoft 365 企业版和 Office 365 企业版。

在 Microsoft 365 中,许可计划 (也称为 SKU 或 Microsoft 365 计划的许可证) 允许用户访问为这些计划定义的 Microsoft 365 服务。 但是,用户可能无权访问当前分配给他们的许可证中可用的所有服务。 可以使用适用于 Microsoft 365 的 PowerShell 查看用户帐户上的服务状态。

有关许可计划、许可证和服务的详细信息,请参阅 使用 PowerShell 查看许可证和服务

使用 Microsoft Graph PowerShell 查看帐户许可证和服务详细信息

首先, 连接到 Microsoft 365 租户

读取用户属性(包括许可证详细信息)需要 User.Read.All 权限范围或“获取用户”图形 API参考页中列出的其他权限之一。

Connect-Graph -Scopes User.ReadWrite.All, Organization.Read.All

接下来,使用此命令列出租户的许可证计划。

Get-MgSubscribedSku

使用这些命令列出每个许可计划中可用的服务。

$allSKUs = Get-MgSubscribedSku -Property SkuPartNumber, ServicePlans 
$allSKUs | ForEach-Object {
    Write-Host "Service Plan:" $_.SkuPartNumber
    $_.ServicePlans | ForEach-Object {$_}
}

使用这些命令列出分配给用户帐户的许可证。

Get-MgUserLicenseDetail -UserId "<user sign-in name (UPN)>"

例如:

Get-MgUserLicenseDetail -UserId "belindan@litwareinc.com"

查看用户帐户的服务

若要查看用户有权访问的所有 Microsoft 365 服务,请使用以下语法:

(Get-MgUserLicenseDetail -UserId <user account UPN> -Property ServicePlans)[<LicenseIndexNumber>].ServicePlans

此示例显示用户 BelindaN@litwareinc.com 有权访问的服务。 这将显示与分配给她帐户的所有许可证关联的服务。

(Get-MgUserLicenseDetail -UserId belindan@litwareinc.com -Property ServicePlans).ServicePlans

此示例显示用户 BelindaN@litwareinc.com 有权从分配给其帐户的第一个许可证访问的服务, (索引号为 0) 。

(Get-MgUserLicenseDetail -UserId belindan@litwareinc.com -Property ServicePlans)[0].ServicePlans

若要查看已分配 多个许可证的用户的所有服务,请使用以下语法:

$userUPN="<user account UPN>"
$allLicenses = Get-MgUserLicenseDetail -UserId $userUPN -Property SkuPartNumber, ServicePlans
$allLicenses | ForEach-Object {
    Write-Host "License:" $_.SkuPartNumber
    $_.ServicePlans | ForEach-Object {$_}
}

另请参阅

使用 PowerShell 管理 Microsoft 365 用户帐户、许可证和组

使用 PowerShell 管理 Microsoft 365

PowerShell for Microsoft 365 入门