使用 PowerShell 檢視Microsoft 365帳戶授權和服務詳細資料
本文適用於 Microsoft 365 企業版和 Office 365 企業版。
在Microsoft 365中,來自授權方案的授權 (也稱為 SKU 或Microsoft 365方案,) 讓使用者能夠存取為這些方案定義的Microsoft 365服務。 不過,使用者可能無法存取目前指派給他們的授權中可用的所有服務。 您可以使用適用于 Microsoft 365 的 PowerShell 來檢視使用者帳戶上的服務狀態。
如需授權方案、授權和服務的詳細資訊,請 參閱使用 PowerShell 檢視授權和服務。
使用 Microsoft Graph PowerShell SDK
讀取使用者屬性,包括授權詳細資料需要 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 {$_}
}
針對 Graph 模組,請使用 Azure Active Directory PowerShell
接下來,使用此命令列出租使用者的授權方案。
Get-AzureADSubscribedSku | Select SkuPartNumber
使用這些命令來列出每個授權方案中可用的服務。
$allSKUs=Get-AzureADSubscribedSku
$licArray = @()
for($i = 0; $i -lt $allSKUs.Count; $i++)
{
$licArray += "Service Plan: " + $allSKUs[$i].SkuPartNumber
$licArray += Get-AzureADSubscribedSku -ObjectID $allSKUs[$i].ObjectID | Select -ExpandProperty ServicePlans
$licArray += ""
}
$licArray
使用這些命令來列出指派給使用者帳戶的授權。
$userUPN="<user account UPN, such as belindan@contoso.com>"
$licensePlanList = Get-AzureADSubscribedSku
$userList = Get-AzureADUser -ObjectID $userUPN | Select -ExpandProperty AssignedLicenses | Select SkuID
$userList | ForEach { $sku=$_.SkuId ; $licensePlanList | ForEach { If ( $sku -eq $_.ObjectId.substring($_.ObjectId.length - 36, 36) ) { Write-Host $_.SkuPartNumber } } }
使用適用於 Windows PowerShell 的 Microsoft Azure Active Directory 模組。
接下來,執行此命令以列出貴組織中可用的授權方案。
Get-MsolAccountSku
注意
PowerShell Core 不支援適用於 Windows PowerShell 的 Microsoft Azure Active Directory 模組和名稱有 Msol 的 Cmdlet。 若要繼續使用這些 Cmdlet,您必須從 Windows PowerShell 執行。
接下來,執行此命令以列出每個授權方案中可用的服務,以及列 (索引編號) 的順序。
(Get-MsolAccountSku | where {$_.AccountSkuId -eq "<AccountSkuId>"}).ServiceStatus
使用此命令來列出指派給使用者的授權,以及 (索引編號) 列出的順序。
Get-MsolUser -UserPrincipalName <user account UPN> | Format-List DisplayName,Licenses
檢視使用者帳戶的服務
若要檢視使用者可存取的所有Microsoft 365服務,請使用下列語法:
(Get-MsolUser -UserPrincipalName <user account UPN>).Licenses[<LicenseIndexNumber>].ServiceStatus
此範例顯示使用者 BelindaN@litwareinc.com 可存取的服務。 這會顯示與指派給其帳戶的所有授權相關聯的服務。
(Get-MsolUser -UserPrincipalName belindan@litwareinc.com).Licenses.ServiceStatus
此範例顯示使用者 BelindaN@litwareinc.com 可從指派給其帳戶的第一個授權存取的服務, (索引編號為 0) 。
(Get-MsolUser -UserPrincipalName belindan@litwareinc.com).Licenses[0].ServiceStatus
若要檢視已指派 多個授權 之使用者的所有服務,請使用下列語法:
$userUPN="<user account UPN>"
$AllLicenses=(Get-MsolUser -UserPrincipalName $userUPN).Licenses
$licArray = @()
for($i = 0; $i -lt $AllLicenses.Count; $i++)
{
$licArray += "License: " + $AllLicenses[$i].AccountSkuId
$licArray += $AllLicenses[$i].ServiceStatus
$licArray += ""
}
$licArray
另請參閱
以 PowerShell 管理 Microsoft 365 使用者帳戶、授權和群組