Hi @주하 김 ,
Thanks for reaching out.
I understand you are trying to assign license to bulk user using PowerShell script.
Yes, it is possible to quickly assign licenses to unlicensed accounts which is required to access any Microsoft 365 services.
Specify the location is the required part of assigning the licenses to the users.
- Create a CSV files with the userPrincipalName of the users you want to assign the licenses.
- Copy and paste the powershell script in powershell window .
- Ensure to update the ‘usagelocation‘ & ‘SkuPartNumber‘ in the script. For Usage Location, Microsoft Follows A2 (ISO) format. SkuPartNumber is the available licensing plans for your organization. For example,
ENTERPRISEPACK
is the license plan name for Office 365 Enterprise E3.
#Assigning and removing licenses for a user requires the User.ReadWrite.All permission scope
Connect-MgGraph -Scopes User.ReadWrite.All, Organization.Read.All
#Import data from csv file
$users = import-csv "C:..\AssignLicence.csv"
#Assign usage location and license based on upn in csv
foreach ($user in $users)
{
$upn=$user.UserPrincipalName
$usagelocation= "IN"
Update-MgUser -UserId $upn -UsageLocation $usagelocation
$e5Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq '
ENTERPRISEPACK'
Set-MgUserLicense -UserId $upn -AddLicenses @{SkuId = $e5Sku.SkuId} -RemoveLicenses @()
}
Hope this will help.
Thanks,
Shweta
Please remember to "Accept Answer" if answer helped you.