PowerShell を使用してライセンスを持つ Microsoft 365 ユーザーとライセンスのない Microsoft 365 ユーザーを表示する

この記事は、Microsoft 365 Enterprise および Office 365 Enterprise の両方に適用されます。

Microsoft 365 organizationのユーザー アカウントには、organizationで利用可能なライセンス プランから、使用可能なライセンスの一部、すべて、または割り当てされていないライセンスが割り当てられている場合があります。 Office 365 PowerShell を使うと、組織内でライセンスのあるユーザーとライセンスのないユーザーをすばやく検索できます。

注:

Azure Active Directory モジュールは、Microsoft Graph PowerShell SDK に置き換えられます。 Microsoft Graph PowerShell SDK を使用して、すべての Microsoft Graph API にアクセスできます。 詳細については、「Microsoft Graph PowerShell SDK の使用を開始する」 を参照してください。

Microsoft Graph PowerShell SDK を使用する

まず、 PowerShell を使用して Microsoft 365 に接続します

ライセンスの詳細を含むユーザー プロパティの読み取りには、User.Read.All アクセス許可スコープ、または参照ページの [ユーザーの取得] Graph API表示されている他のアクセス許可のいずれかが必要です。

テナントで使用できるライセンスを読み取るために、Organization.Read.All アクセス許可スコープが必要です。

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

特定のユーザー アカウントのライセンスの詳細を表示するには、次のコマンドを実行します。

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

例:

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

ライセンス プラン (ライセンスのないユーザー) が割り当てられていないorganization内のすべてのユーザー アカウントの一覧を表示するには、次のコマンドを実行します。

Get-MgUser -Filter 'assignedLicenses/$count eq 0' -ConsistencyLevel eventual -CountVariable unlicensedUserCount -All

Write-Host "Found $unlicensedUserCount unlicensed users."

ライセンス プラン (ライセンスのないユーザー) が割り当てられていないorganization内のすべてのメンバー ユーザー アカウント (ゲストを除く) の一覧を表示するには、次のコマンドを実行します。

Get-MgUser -Filter "assignedLicenses/`$count eq 0 and userType eq 'Member'" -ConsistencyLevel eventual -CountVariable unlicensedUserCount -All

Write-Host "Found $unlicensedUserCount unlicensed users (excluding guests)."

ライセンス プラン (ライセンスユーザー) が割り当てられているorganization内のすべてのユーザー アカウントの一覧を表示するには、次のコマンドを実行します。

Get-MgUser -Filter 'assignedLicenses/$count ne 0' -ConsistencyLevel eventual -CountVariable licensedUserCount -All -Select UserPrincipalName,DisplayName,AssignedLicenses | Format-Table -Property UserPrincipalName,DisplayName,AssignedLicenses

Write-Host "Found $licensedUserCount licensed users."

E5 ライセンスが割り当てられているorganization内のすべてのユーザー アカウントの一覧を表示するには、次のコマンドを実行します。

$e5Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'SPE_E5'

Get-MgUser -Filter "assignedLicenses/any(x:x/skuId eq $($e5sku.SkuId) )" -ConsistencyLevel eventual -CountVariable e5licensedUserCount -All

Write-Host "Found $e5licensedUserCount E5 licensed users."

関連項目

Microsoft 365 ユーザー アカウント、ライセンス、PowerShell を使用したグループを管理する

PowerShell で Microsoft 365を管理する

Microsoft 365 用 PowerShell の使用を開始する