在此前的一篇文章中,我们讨论了如何通过脚本和 .csv 表格的方式批量地为用户分配 Microsoft 365 的 license,文章链接请见这里:
Microsoft 365 国际版通过脚本批量分配 License - iRabit
但是那篇文章适用于国际版的 Microsoft 365,如果你正在使用的是世纪互联版的 Microsoft 365,那么通过上一篇文章的步骤是无法完成 license 的分配的。
其实上面文章的绝大部分脚本代码都可以与世纪互联版的 Microsoft 365 通用,只是在登录的环节会和国际版的不太一样。
如果要登录到世纪互联版 Microsoft 365,我们需要给连接 MsOnline 的命令加一个参数,即:
-AzureEnvironment AzureChinaCloud
这个参数的作用是指定你的环境为中国的世纪互联云。
那么基于这个原理,我们的脚本就需要做出一些修改了。
请参考以下代码:
#Session to Microsoft Azure AD (Use if Azure AD session inactive)
$msolcred = get-credential
connect-msolservice -AzureEnvironment AzureChinaCloud -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= "syndication-account:ENTERPRISEPACK_NO_RMS" #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
}
同样地,批量移除 license 则可以参考以下代码:
#Session to Microsoft Azure AD (Use if Azure AD session inactive)
$msolcred = get-credential
connect-msolservice -AzureEnvironment AzureChinaCloud -credential $msolcred
#Import data from CSV file
$users = import-csv ".\RemoveLicense.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= "syndication-account:ENTERPRISEPACK_NO_RMS" #Ensure to enter the correct AccountSkuID based on your SkuID
Set-MsolUser -UserPrincipalName $upn -UsageLocation $usagelocation
Set-MsolUserLicense -UserPrincipalName $upn -RemoveLicenses $SKU
Write-Host "License Removed from UPN:"$upn #Return which UserPrincipalName was successfully assigned with the license
}
不用谢。