1. 安装 MsOnline 管理模块:
 
Install-Module MSOnline
 
2. 连接到 MsOnline 管理命令行:
 
$msolcred = Get-Credential
Connect-MsolService -Credential $msolcred
 
 
3. 确定要分配的 License 的 SKU ID
 
Get-MsolAccountSku
 
 
4. 建立需要分配 License 的用户的 csv 表格,命名为 AssignLicense.csv。
 
格式:
 
UserPrincipalName
user001@irabit.org
user002@irabit.org
 
 
5. 将以下内容保存为 AssignLicenseScript.ps1 脚本(注意替换 usagelocation 和 SKU):
 
#Session to Microsoft Azure AD (Use if Azure AD session inactive)
$msolcred = get-credential
connect-msolservice -credential $msolcred
	 
#Import data from CSV file
    $users = import-csv ".\AssignLicense.csv"
#Assign License & Location based on UserPrincipalName from the CSV.   
    foreach ($user in $users)
    {
        $upn=$user.UserPrincipalName
        $usagelocation= "CN"  #Ensure to enter the correct location based on your user/organization location
        $SKU= "itoolsoft:DEVELOPERPACK_E5" #Ensure to enter the correct AccountSkuID based on your SkuID
        Set-MsolUser -UserPrincipalName $upn -UsageLocation $usagelocation
        Set-MsolUserLicense -UserPrincipalName $upn -AddLicenses $SKU
        Write-Host "License Assigned to UPN:"$upn #Return which UserPrincipalName was successfully assigned with the license
    } 
 
6. 把 .csv 文件和 .ps1 文件放在一个路径下,cd 到那个路径。
 
 
7. 运行以下命令:
 
Set-ExecutionPolicy RemoteSigned
 
8. 运行 AssignLicenseScript.ps1。
 
 
9. 检查 Liense 是否 assign 成功。
 
 
好了。