From ec52c511e54be77233da52f96b7ebf4211d1fbdb Mon Sep 17 00:00:00 2001 From: Octavio Morales Date: Tue, 15 Oct 2024 10:17:40 -0600 Subject: [PATCH] Update remove-licenses-from-user-accounts-with-microsoft-365-powershell.md - Changed the remove specific license from a list of users to use a CSV file instead a text file. --- ...om-user-accounts-with-microsoft-365-powershell.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/microsoft-365/enterprise/remove-licenses-from-user-accounts-with-microsoft-365-powershell.md b/microsoft-365/enterprise/remove-licenses-from-user-accounts-with-microsoft-365-powershell.md index e7e6d101f9d..6089697b954 100644 --- a/microsoft-365/enterprise/remove-licenses-from-user-accounts-with-microsoft-365-powershell.md +++ b/microsoft-365/enterprise/remove-licenses-from-user-accounts-with-microsoft-365-powershell.md @@ -84,11 +84,12 @@ foreach($user in $licensedUsers) } ``` -To remove a specific license from a list of users in a text file, perform the following steps. This example removes the **SPE_E5** (Microsoft 365 Enterprise E5) license from the user accounts defined in the text file C:\My Documents\Accounts.txt. +To remove a specific license from a list of users in a `CSV` file, perform the following steps. This example removes the **SPE_E5** (Microsoft 365 Enterprise E5) license from the user accounts defined in the `CSV` file C:\My Documents\Accounts.csv. - 1. Create and save a text file to C:\My Documents\Accounts.txt that contains one account on each line like this: + 1. Create and save a CSV file to C:\My Documents\Accounts.csv that contains one account on each line under the `UserPrincipalName` header like this: ```powershell + UserPrincipalName akol@contoso.com tjohnston@contoso.com kakers@contoso.com @@ -97,11 +98,10 @@ To remove a specific license from a list of users in a text file, perform the fo 2. Use the following command: ```powershell - $x=Get-Content "C:\My Documents\Accounts.txt" + $usersList = Import-CSV -Path "C:\My Documents\Accounts.csv" $e5Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'SPE_E5' - for ($i=0; $i -lt $x.Count; $i++) - { - Set-MgUserLicense -UserId $x[$i] -RemoveLicenses @($e5Sku.SkuId) -AddLicenses @{} + foreach($user in $usersList) { + Set-MgUserLicense -UserId $user.UserPrincipalName -RemoveLicenses @($e5Sku.SkuId) -AddLicenses @{} } ```