【问题标题】:Assign multiple o365 licenses to a single user using PowerShell使用 PowerShell 将多个 o365 许可证分配给单个用户
【发布时间】:2022-02-12 08:09:57
【问题描述】:

我正在使用一个简单的 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 许可证添加到测试用户。

【问题讨论】:

    标签: powershell office365


    【解决方案1】:

    您可以将另一个文件添加到您的 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
    

    【讨论】:

      【解决方案2】:

      我使用一个简单的脚本来添加多个许可证。唯一需要的信息是 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
      }
      

      您可以根据自己的需要进行调整。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-17
        • 2022-12-17
        • 1970-01-01
        • 1970-01-01
        • 2019-06-17
        • 2014-11-29
        • 1970-01-01
        相关资源
        最近更新 更多