Tuesday, January 21, 2025

How to retrieve a list of users who have both PowerApps Premium and Power Automate Premium licenses. Could you please provide a solution using either a PowerShell script or a Power Automate flow to accomplish this?

 To retrieve a list of users who have both PowerApps Premium and Power Automate Premium licenses, you can use a PowerShell script. Below is a step-by-step guide to accomplish this. The script will use the Microsoft Graph API to query the necessary license details.

Prerequisites

  1. Microsoft Graph PowerShell Module: Ensure you have the Microsoft.Graph PowerShell module installed.
  2. Admin Permissions: Ensure you have the required permissions to query user licenses.
  3. Azure AD App Registration: Register an app in Azure AD and grant the necessary API permissions to read user licenses.

Steps

  1. Install Microsoft Graph PowerShell Module:

PowerShell

Install-Module Microsoft.Graph -Scope CurrentUser

  1. Connect to Microsoft Graph:

PowerShell

Connect-MgGraph -Scopes "User.Read.All"

  1. PowerShell Script:

PowerShell

# Define the SKU IDs for PowerApps Premium and Power Automate Premium

$PowerAppsPremiumSkuId = "c68f8d98-5534-43a8-9110-0d174bc7c6e3" # Replace with actual SKU ID for PowerApps Premium

$PowerAutomatePremiumSkuId = "9c0dab89-a30c-4bfd-8a92-6dff3f1d8d04" # Replace with actual SKU ID for Power Automate Premium

 

# Get all users in the organization

$users = Get-MgUser -All

 

# Filter users who have both licenses

$usersWithBothLicenses = @()

foreach ($user in $users) {

    # Get the user's license details

    $userLicenseDetails = Get-MgUserLicenseDetails -UserId $user.Id

 

    # Check if the user has both licenses

    $hasPowerAppsPremium = $userLicenseDetails.SkuId -contains $PowerAppsPremiumSkuId

    $hasPowerAutomatePremium = $userLicenseDetails.SkuId -contains $PowerAutomatePremiumSkuId

 

    if ($hasPowerAppsPremium -and $hasPowerAutomatePremium) {

        $usersWithBothLicenses += $user

    }

}

 

# Output the list of users with both licenses

$usersWithBothLicenses | Select-Object DisplayName, UserPrincipalName

Explanation

  • SKU IDs: Replace the placeholders for PowerAppsPremiumSkuId and PowerAutomatePremiumSkuId with the actual SKU IDs for those licenses. You can retrieve the SKU IDs by listing all available licenses using the Graph API.
  • Get-MgUser: Retrieves all users in the organization.
  • Get-MgUserLicenseDetails: Retrieves the license details for each user.
  • Filtering: The script checks if each user has both the PowerApps Premium and Power Automate Premium licenses. If so, the user is added to the list.

Running the Script

  1. Open PowerShell with administrative privileges.
  2. Run the script above.
  3. The script will output the list of users who have both PowerApps Premium and Power Automate Premium licenses.

 

 


No comments:

DeepSeek vs OpenAI

DeepSeek vs OpenAI Two companies have recently drawn a lot of interest in the quickly changing field of artificial intelligence (AI): Op...