O365批量许可证

时间:2016-08-11 21:37:03

标签: powershell azure active-directory office365 licensing

我使用下面的PowerShell脚本通过.csv文件许可office365中的批量用户。该脚本仅在.csv文件头为:

时才有效

的UserPrincipalName
example@jackson.k12.ms.us

但是我们的.csv格式化了:" Alias"," UPN"

                     "myrobinson","myrobinson@jackson.k12.ms.us"

我想知道如何重新编码此脚本,以便它与.csv文件一起使用?

$path= Import-Csv -Path "\\11.10.38.142\Users\myrobinson\NewUsers.csv"
foreach ($item in $path){

$MSOLUserName= $item.UserPrincipalName

$password = ConvertTo-SecureString "support@Jpsd" -AsPlainText –Force

$credential = New-Object System.Management.Automation.PsCredential("admin@jpsd.onmicrosoft.com",$password)

$cred = Get-Credential -cred $credential

Import-Module MSOnline

Connect-Msolservice -cred $cred

$AccountSkuId = "jpsd:STANDARDWOFFPACK_FACULTY" 

$UsageLocation = "US" 

$LicenseOptions = New-MsolLicenseOptions -AccountSkuId $AccountSkuId 

Set-MsolUser -UserPrincipalName $MSOLUserName -UsageLocation $UsageLocation

Set-MsolUserLicense -UserPrincipalName $MSOLUserName -AddLicenses 

$AccountSkuId  -LicenseOptions $LicenseOptions

}

1 个答案:

答案 0 :(得分:0)

只需用$ item.UPN替换$ item.UserPrincipalName。