I understand your concern. The transition from Set-MsolUserLicense to Set-MgUserLicense requires some changes in the way you manage user licenses. Here’s a general approach to handle this:
Get the User ID: Since Set-MgUserLicense requires the User ID instead of the User Principal Name (UPN), you’ll need to first retrieve the User ID. You can do this by using the Get-MgUser cmdlet with the UPN, and then extract the Id property.
- Get the License SKU ID: To get the
Licenses.AccountSkuId, you can use the Get-MgUserLicenseDetail cmdlet. This cmdlet returns the license details of a specific user account, including the SKU ID.
- Set the User License: Once you have the User ID and the License SKU ID, you can use the
Set-MgUserLicense cmdlet to add or remove licenses.
Here’s a sample script that illustrates these steps:
# Connect to Microsoft Graph
Connect-Graph -Scopes User.ReadWrite.All, Organization.Read.All
# Get the User ID
$userId = (Get-MgUser -UserPrincipalName "******@domain.com").Id
# Get the License SKU ID
$licenseSkuId = (Get-MgSubscribedSku | Where-Object SkuPartNumber -eq 'YOUR_LICENSE_NAME').SkuId
# Set the User License
Set-MgUserLicense -UserId $userId -AddLicenses @{"SkuId" = $licenseSkuId} -RemoveLicenses @("old pool")
Please replace "******@domain.com" and 'YOUR_LICENSE_NAME' with the actual UPN and license name you want to assign. Also, replace "old pool" with the actual old pool you want to remove.
Remember to handle errors and edge cases according to your needs. This is just a basic example and might need adjustments based on your specific requirements.
Please note that you need appropriate permissions to run these cmdlets. For Set-MgUserLicense, you need User.ReadWrite.All permission scope. For Get-MgUserLicenseDetail, you need User.Read.All permission scope.
I hope this helps! Let me know if you have any other questions.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".