Published: 31.Mar 2020
Categories:

Assign direct license to multiple users via PowerShell

Hi there .. with this short script you can assign license directly to users from CSV/TXT file.

Prepare CSV file with UserPrincipalName as Header and then save it to your desktop as users.csv

First you need to find out AccountSkuId of a license. We can get it with Get-MsolAccountSku cmdlet.

PowerShell Get-MsolAccountSku

Then start the script with AccountSkuId as a parameter:

.\AssignLicenseCSV.ps1 reseller-account:POWER_BI_STANDARD
Code language: CSS (css)

Script

param(
  [Parameter(Mandatory = $true, Position = 1)]
  $script:License
)

Clear-Host
 
$CSVfile    = "$env:USERPROFILE\Desktop\users.csv"
#$License    = "reseller-account:POWER_BI_STANDARD" #Power BI (Free)
 
# IMPORT USERS
Write-Progress -Activity "Importing users.."
$users = Import-Csv $CSVfile
Write-Host $users.count "users were imported." -ForegroundColor Green
 
Start-Sleep -Seconds 2
 
# SET LICENSE FOR EACH USER
foreach ($user in $users)
{
    $upn = $user.UserPrincipalName
    Set-MsolUserLicense -UserPrincipalName $upn -AddLicenses $License
    Write-Progress -Activity "Adding licenses.." -CurrentOperation $upn
}

Write-Host "Script done.." -ForegorundColor Green
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
PowerAddict.net - Lubomir Goban  ---  Find me on - 
LinkedIn
0
Would love your thoughts, please comment.x
()
x