Assigning Power BI Licenses using PowerShell

Loading

Managing Power BI licenses for users is a crucial task for IT administrators. Using PowerShell, you can efficiently assign, remove, or check Power BI licenses for users in Microsoft 365.

This guide provides a step-by-step approach to assigning Power BI licenses using Microsoft Graph PowerShell or AzureAD PowerShell Module.


Step 1: Prerequisites

Before assigning licenses, ensure you have the following:

1. Required Permissions

You must be a Global Administrator or License Administrator in Microsoft 365.

2. Install PowerShell Modules

Using Microsoft Graph PowerShell (Recommended)

# Install Microsoft Graph PowerShell module
Install-Module Microsoft.Graph -Scope CurrentUser -Force

# Import the module
Import-Module Microsoft.Graph

Using AzureAD PowerShell (Legacy)

# Install Azure AD module
Install-Module AzureAD -Scope CurrentUser -Force

# Import the module
Import-Module AzureAD

Step 2: Connect to Microsoft 365

To assign licenses, first, authenticate to Microsoft 365.

Using Microsoft Graph PowerShell

Connect-MgGraph -Scopes User.Read.All, Organization.Read.All, Directory.ReadWrite.All

Using AzureAD PowerShell

powershellCopyEditConnect-AzureAD

You are now connected!


Step 3: Retrieve Available Power BI Licenses

To assign a license, you need the SKU ID of the Power BI license in your tenant.

Using Microsoft Graph PowerShell

# Get all available licenses in your tenant
Get-MgSubscribedSku | Select-Object SkuId, SkuPartNumber

Using AzureAD PowerShell

# Get available licenses
Get-AzureADSubscribedSku | Select-Object SkuId, SkuPartNumber

Example Output

SkuId                                  SkuPartNumber
------------------------------------ ------------------
1234abcd-5678-90ef-ghij-klmnoprstuvw POWER_BI_PRO
abcd5678-1234-efgh-ijkl-mnopqrstuvwx POWER_BI_PREMIUM_PER_USER

You now have the SKU IDs for Power BI licenses!


Step 4: Assign a Power BI License to a User

Using Microsoft Graph PowerShell

# Define user and license SKU ID
$userId = "user@example.com"
$licenseSkuId = "1234abcd-5678-90ef-ghij-klmnoprstuvw" # POWER_BI_PRO

# Assign the license
Set-MgUserLicense -UserId $userId -AddLicenses @{SkuId=$licenseSkuId} -RemoveLicenses @()

Using AzureAD PowerShell

# Define user and license SKU ID
$userId = "user@example.com"
$licenseSkuId = "1234abcd-5678-90ef-ghij-klmnoprstuvw" # POWER_BI_PRO

# Assign the license
$license = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$license.SkuId = $licenseSkuId
$licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$licenses.AddLicenses = $license
$licenses.RemoveLicenses = @()

# Apply the license
Set-AzureADUserLicense -ObjectId $userId -AssignedLicenses $licenses

User successfully assigned a Power BI license!


Step 5: Assign Power BI Licenses in Bulk

If you need to assign licenses to multiple users:

Using Microsoft Graph PowerShell

# Read user emails from a CSV file
$users = Import-Csv "C:\PowerBI_Users.csv"

# Loop through each user and assign a license
foreach ($user in $users) {
Set-MgUserLicense -UserId $user.Email -AddLicenses @{SkuId="1234abcd-5678-90ef-ghij-klmnoprstuvw"} -RemoveLicenses @()
}

Using AzureAD PowerShell

# Read user emails from a CSV file
$users = Import-Csv "C:\PowerBI_Users.csv"

# Loop through each user and assign a license
foreach ($user in $users) {
$license = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$license.SkuId = "1234abcd-5678-90ef-ghij-klmnoprstuvw"
$licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$licenses.AddLicenses = $license
$licenses.RemoveLicenses = @()

Set-AzureADUserLicense -ObjectId $user.Email -AssignedLicenses $licenses
}

All users in the CSV file are now licensed!


Step 6: Verify Assigned Licenses

To check if a user has a Power BI license:

Using Microsoft Graph PowerShell

# Check user licenses
Get-MgUserLicenseDetail -UserId "user@example.com" | Select-Object SkuPartNumber

Using AzureAD PowerShell

# Get user license details
(Get-AzureADUserLicenseDetail -ObjectId "user@example.com").SkuPartNumber

User license verified successfully!


Step 7: Remove a Power BI License from a User

If you need to remove a Power BI license:

Using Microsoft Graph PowerShell

# Remove Power BI Pro license from a user
Set-MgUserLicense -UserId "user@example.com" -AddLicenses @() -RemoveLicenses @("1234abcd-5678-90ef-ghij-klmnoprstuvw")

Using AzureAD PowerShell

# Remove Power BI Pro license
$licenseSkuId = "1234abcd-5678-90ef-ghij-klmnoprstuvw"
$licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$licenses.AddLicenses = @()
$licenses.RemoveLicenses = @($licenseSkuId)

Set-AzureADUserLicense -ObjectId "user@example.com" -AssignedLicenses $licenses

Power BI license removed from the user!


Step 8: Export a List of Users with Power BI Licenses

To generate a report of users with Power BI licenses:

Using Microsoft Graph PowerShell

# Get all users with Power BI licenses
$powerBILicenseId = "1234abcd-5678-90ef-ghij-klmnoprstuvw"

$users = Get-MgUser -All | Where-Object {
(Get-MgUserLicenseDetail -UserId $_.Id).SkuId -contains $powerBILicenseId
}

# Export to CSV
$users | Select-Object DisplayName, UserPrincipalName | Export-Csv "C:\PowerBI_Licensed_Users.csv" -NoTypeInformation

Power BI licensed users list exported!


Step 9: Disconnect from Microsoft 365

Once done, disconnect from the session:

Disconnect-MgGraph   # For Microsoft Graph
Disconnect-AzureAD # For Azure AD

Disconnected successfully!

Leave a Reply

Your email address will not be published. Required fields are marked *