使用 PowerShell 将多个 o365 许可证分配给单个用户
Assign multiple o365 licenses to a single user using PowerShell
我正在使用一个简单的 Powershell 脚本将新用户添加到 O365 并分配许可证。但是我试图一次向单个用户添加多个许可证。
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
DisplayName,FirstName,LastName,UserPrincipalName,Usagelocation,AccountSkuId
Test Jesse,Tes,Jesse,test.jesse@(tenant).nl,NL,(tenant):EMS
对于此示例,我想将 EMS 和 ENTERPRISEPACK 许可证添加到测试用户。
您可以将另一个文件添加到您的 CSV 文件中:
DisplayName,FirstName,LastName,UserPrincipalName,Usagelocation,AccountSkuIdEMS, AccountSkuIdENTERPRISEPACK
Test Jesse,Tes,Jesse,test.jesse@(tenant).nl,NL,(tenant):EMS,(tenant):ENTERPRISEPACK
并调整脚本:
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
我使用一个简单的脚本来添加多个许可证。唯一需要的信息是 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
}
您可以根据自己的需要进行调整。
我正在使用一个简单的 Powershell 脚本将新用户添加到 O365 并分配许可证。但是我试图一次向单个用户添加多个许可证。
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
DisplayName,FirstName,LastName,UserPrincipalName,Usagelocation,AccountSkuId
Test Jesse,Tes,Jesse,test.jesse@(tenant).nl,NL,(tenant):EMS
对于此示例,我想将 EMS 和 ENTERPRISEPACK 许可证添加到测试用户。
您可以将另一个文件添加到您的 CSV 文件中:
DisplayName,FirstName,LastName,UserPrincipalName,Usagelocation,AccountSkuIdEMS, AccountSkuIdENTERPRISEPACK
Test Jesse,Tes,Jesse,test.jesse@(tenant).nl,NL,(tenant):EMS,(tenant):ENTERPRISEPACK
并调整脚本:
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
我使用一个简单的脚本来添加多个许可证。唯一需要的信息是 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
}
您可以根据自己的需要进行调整。