简体   繁体   English

使用 PowerShell 将多个 o365 许可证分配给单个用户

[英]Assign multiple o365 licenses to a single user using PowerShell

I'm using a simple Powershell script to add new users to O365 and assign a license.我正在使用一个简单的 Powershell 脚本将新用户添加到 O365 并分配许可证。 However im trying to add multiple licenses at once to a single user.但是我试图一次向单个用户添加多个许可证。

Powershell Powershell

Connect-MsolService -Credential $UserCredential

Import-Csv -Path "C:\Users\Jesse\Documents\Powershell\NewAccounts.csv" | foreach {New-MsolUser -DisplayName $_.DisplayName -FirstName $_.FirstName -LastName $_.LastName -UserPrincipalName $_.UserPrincipalName -UsageLocation $_.UsageLocation -LicenseAssignment $_.AccountSkuId} | Export-Csv -Path "C:\Users\Jesse\Documents\Powershell\NewAccountResults.csv" -Verbose

.CSV .CSV

DisplayName,FirstName,LastName,UserPrincipalName,Usagelocation,AccountSkuId
Test Jesse,Tes,Jesse,test.jesse@(tenant).nl,NL,(tenant):EMS

For this example i'd like to add the EMS & ENTERPRISEPACK license to the test user.对于此示例,我想将 EMS 和 ENTERPRISEPACK 许可证添加到测试用户。

You can add another filed to your CSV:您可以在 CSV 中添加另一个文件:

DisplayName,FirstName,LastName,UserPrincipalName,Usagelocation,AccountSkuIdEMS, AccountSkuIdENTERPRISEPACK
Test Jesse,Tes,Jesse,test.jesse@(tenant).nl,NL,(tenant):EMS,(tenant):ENTERPRISEPACK

And tweak the script:并调整脚本:

Import-Csv -Path "C:\Users\Jesse\Documents\Powershell\NewAccounts.csv" | foreach {New-MsolUser -DisplayName $_.DisplayName -FirstName $_.FirstName -LastName $_.LastName -UserPrincipalName $_.UserPrincipalName -UsageLocation $_.UsageLocation -LicenseAssignment $_.AccountSkuIdEMS,$_.AccountSkuIdENTERPRISEPACK} | Export-Csv -Path "C:\Users\Jesse\Documents\Powershell\NewAccountResults.csv" -Verbose

I use a simple script to add multiple licenses.我使用一个简单的脚本来添加多个许可证。 Only information needed is the UPN, which in my environment is the mail address.唯一需要的信息是 UPN,在我的环境中它是邮件地址。

Connect-MsolService
Import-Csv 'C:\usersmailaddress.CSV' | foreach {Set-MsolUser -UserPrincipalName $_.EmailAdress -UsageLocation BR
Set-MsolUserLicense -UserPrincipalName $_.EmailAdress -AddLicenses mydomain:ENTERPRISEPACK
Set-MsolUserLicense -UserPrincipalName $_.EmailAdress -AddLicenses mydomain:EMS
}

You can adapt it to your needs.您可以根据自己的需要进行调整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM