ユーザー ライセンスの割り当て中に Microsoft 365 サービスへのアクセスを無効にする

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

Microsoft 365 サブスクリプションには、個々のサービスのサービス プランが付属しています。 Microsoft 365 管理者は、多くの場合、ユーザーにライセンスを割り当てるときに特定のプランを無効にする必要があります。 この記事の手順では、個々のユーザー アカウントまたは複数のユーザー アカウントに対して PowerShell を使用して特定のサービス プランを無効にしながら、Microsoft 365 ライセンスを割り当てることができます。

Graph 用 Azure Active Directory PowerShell モジュールを使用する

まず、Microsoft 365 テナントに接続します

次に、このコマンドを使用して、テナントのライセンス プランを一覧表示します。

Get-AzureADSubscribedSku | Select SkuPartNumber

注:

Azure AD Powershell は、2024 年 3 月 30 日に非推奨となる予定です。 詳細については、 非推奨の更新プログラムに関するページを参照してください。

Microsoft Entra ID (旧称 Azure AD) と対話するには、Microsoft Graph PowerShell に移行することをお勧めします。 Microsoft Graph PowerShell では、すべての Microsoft Graph API へのアクセスが許可され、PowerShell 7 で利用できます。 一般的な移行クエリに対する回答については、「 移行に関する FAQ」を参照してください。

次に、ライセンスを追加するアカウントのサインイン名 (ユーザー プリンシパル名 (UPN) とも呼ばれます) を取得します。

次に、有効にするサービスの一覧をコンパイルします。 ライセンス プラン (製品名とも呼ばれます) の完全な一覧、含まれているサービス プラン、および対応するフレンドリ名については、 ライセンスの製品名とサービス プラン識別子に関するページを参照してください。

以下のコマンド ブロックに対して、ユーザー アカウントのユーザー プリンシパル名、SKU パーツ番号、および説明テキストと 文字と 文字を有効にして削除するサービス プランの一覧を<>入力します。 次に、完成したコマンドを PowerShell コマンド プロンプトで実行します。

$userUPN="<user account UPN>"
$skuPart="<SKU part number>"
$serviceList=<double-quoted enclosed, comma-separated list of enabled services>
$user = Get-AzureADUser -ObjectID $userUPN
$skuID= (Get-AzureADSubscribedSku  | Where {$_.SkuPartNumber -eq $skuPart}).SkuID
$SkuFeaturesToEnable = @($serviceList)
$StandardLicense = Get-AzureADSubscribedSku | Where {$_.SkuId -eq $skuID}
$SkuFeaturesToDisable = $StandardLicense.ServicePlans | ForEach-Object { $_ | Where {$_.ServicePlanName -notin $SkuFeaturesToEnable }}
$License = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$License.SkuId = $StandardLicense.SkuId
$License.DisabledPlans = $SkuFeaturesToDisable.ServicePlanId
$LicensesToAssign = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$LicensesToAssign.AddLicenses = $License
Set-AzureADUserLicense -ObjectId $user.ObjectId -AssignedLicenses $LicensesToAssign

Windows PowerShellにMicrosoft Azure Active Directory モジュールを使用する

まず、Microsoft 365 テナントに接続します

次に、次のコマンドを実行して、現在のサブスクリプションを確認します。

Get-MsolAccountSku

注:

PowerShell Core では、Windows PowerShell モジュールとコマンドレットの名前に Msol を含むMicrosoft Azure Active Directory モジュールはサポートされていません。 これらのコマンドレットを引き続き使用するには、Windows PowerShell から実行する必要があります。

コマンドの表示で、次のコマンドを Get-MsolAccountSku 実行します。

  • AccountSkuId は、OrganizationName>:<Subscription 形式の<organizationのサブスクリプション>です。 <OrganizationName> は、Microsoft 365 に登録したときに指定した値であり、organizationに対して一意です。 [ <サブスクリプション]> の値は、特定のサブスクリプション用です。 たとえば、litwareinc:ENTERPRISEPACK の場合、organization名は litwareinc で、サブスクリプション名は ENTERPRISEPACK (Office 365 Enterprise E3) です。

  • ActiveUnits は、サブスクリプションで購入したライセンス数です。

  • WarningUnits は、まだ更新しておらず、30 日の猶予期間を過ぎると有効期限切れになる、サブスクリプション内のライセンス数です。

  • ConsumedUnits は、このサブスクリプションでユーザーに割り当てたライセンスの数です。

ライセンスを付与するユーザーを含む Microsoft 365 サブスクリプションの AccountSkuId に注意してください。 また、割り当てる十分な数のライセンスがあることも確認します (ActiveUnits から ConsumedUnits を減算します)。

次に、次のコマンドを実行して、すべてのサブスクリプションで利用可能な Microsoft 365 サービス プランの詳細を確認します。

Get-MsolAccountSku | Select -ExpandProperty ServiceStatus

このコマンドの出力に基づいて、ユーザーにライセンスを割り当てるときに無効にするサービス プランを判別します。

サービス プランとそれに対応する Microsoft 365 サービスの一部を次に示します。

次の表は、Microsoft 365 サービス プランと、最も一般的なサービスのフレンドリ名を示しています。 実際のサービス プランの一覧とは、異なる場合があります。

サービス プラン 説明
SWAY
Sway
TEAMS1
Microsoft Teams
YAMMER_ENTERPRISE
Viva Engage
RMS_S_ENTERPRISE
Azure Rights Management (RMS)
OFFICESUBSCRIPTION
Microsoft 365 Apps for enterprise (以前の名前は Office 365 ProPlus)
MCOSTANDARD
Skype for Business Online
SHAREPOINTWAC
事業所
SHAREPOINTENTERPRISE
SharePoint Online
EXCHANGE_S_ENTERPRISE
Exchange Online プラン 2

ライセンス プラン (製品名とも呼ばれます) の完全な一覧、含まれているサービス プラン、および対応するフレンドリ名については、 ライセンスの製品名とサービス プラン識別子に関するページを参照してください。

この時点で、AccountSkuId と無効にするサービス プランが決まったため、1 ユーザーまたは複数ユーザーにライセンスを割り当てることができます。

単一ユーザーの場合

1 人のユーザーの場合は、ユーザー アカウントのユーザー プリンシパル名、AccountSkuId、説明テキストと 文字と 文字を無効にして削除するサービス プランの一覧を<>入力します。 次に、完成したコマンドを PowerShell コマンド プロンプトで実行します。

$userUPN="<the user's account name in email format>"
$accountSkuId="<the AccountSkuId from the Get-MsolAccountSku command>"
$planList=@( <comma-separated, double-quote enclosed list of the service plans to disable> )
$licenseOptions=New-MsolLicenseOptions -AccountSkuId $accountSkuId -DisabledPlans $planList
Set-MsolUserLicense -UserPrincipalName $userUpn -AddLicenses $accountSkuId -ErrorAction SilentlyContinue
Sleep -Seconds 5
Set-MsolUserLicense -UserPrincipalName $userUpn -LicenseOptions $licenseOptions -ErrorAction SilentlyContinue

contoso:ENTERPRISEPACK ライセンスの 、 という名前 belindan@contoso.comのアカウントのコマンド ブロックの例を次に示します。無効にするサービス プランは、RMS_S_ENTERPRISE、SWAY、INTUNE_O365、YAMMER_ENTERPRISEです。

$userUPN="belindan@contoso.com"
$accountSkuId="contoso:ENTERPRISEPACK"
$planList=@( "RMS_S_ENTERPRISE","SWAY","INTUNE_O365","YAMMER_ENTERPRISE" )
$licenseOptions=New-MsolLicenseOptions -AccountSkuId $accountSkuId -DisabledPlans $planList
Set-MsolUserLicense -UserPrincipalName $userUpn -AddLicenses $accountSkuId -ErrorAction SilentlyContinue
Sleep -Seconds 5
Set-MsolUserLicense -UserPrincipalName $userUpn -LicenseOptions $licenseOptions -ErrorAction SilentlyContinue

複数ユーザーの場合

この管理タスクを複数ユーザーに実行するには、UserPrincipalName フィールドと UsageLocation フィールドが含まれるコンマ区切り値 (CSV) テキスト ファイルを作成します。 次に例を示します。

UserPrincipalName,UsageLocation
ClaudeL@contoso.onmicrosoft.com,FR
LynneB@contoso.onmicrosoft.com,US
ShawnM@contoso.onmicrosoft.com,US

その後、入力および出力の各 CSV ファイルの場所、アカウント SKU ID、無効にするサービス プランの一覧を入力し、完成したコマンドを PowerShell コマンド プロンプトで実行します。

$inFileName="<path and file name of the input CSV file that contains the users, example: C:\admin\Users2License.CSV>"
$outFileName="<path and file name of the output CSV file that records the results, example: C:\admin\Users2License-Done.CSV>"
$accountSkuId="<the AccountSkuId from the Get-MsolAccountSku command>"
$planList=@( <comma-separated, double-quote enclosed list of the plans to disable> )
$users=Import-Csv $inFileName
$licenseOptions=New-MsolLicenseOptions -AccountSkuId $accountSkuId -DisabledPlans $planList
ForEach ($user in $users)
{
$user.Userprincipalname
$upn=$user.UserPrincipalName
Set-MsolUserLicense -UserPrincipalName $upn -AddLicenses $accountSkuId -ErrorAction SilentlyContinue
sleep -Seconds 5
Set-MsolUserLicense -UserPrincipalName $upn -LicenseOptions $licenseOptions -ErrorAction SilentlyContinue
$users | Get-MsolUser | Select UserPrincipalName, Islicensed,Usagelocation | Export-Csv $outFileName
}

この PowerShell コマンド ブロックは以下の処理を行います。

  • 各ユーザーのユーザー プリンシパル名を表示します。

  • 各ユーザーにカスタマイズされたライセンスを割り当てます。

  • 処理されたすべてのユーザーが含まれる CSV ファイルを作成し、そのライセンス状態を示します。

関連項目

PowerShell を使用して Microsoft 365 サービスへのアクセスを無効にする

PowerShell を使用してSwayへのアクセスを無効にする

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

PowerShell で Microsoft 365を管理する