Create a role-assignable group , add the required members and assign to the role needed and assign the license to that:
Gell all users from a domain
Naoufel OULD LACHHAB
20
Reputation points
Hello,
how to get all users in domain with MS graph ?
thank you
Accepted answer
1 additional answer
Sort by: Most helpful
-
Deepanshukatara-6769 10,690 Reputation points
2024-06-27T09:11:41.1666667+00:00 To dynamically assign P2 licenses for users assigned to Privileged Identity Management (PIM)
You can assign licenses through PowerShell.
To automate license assignment using PowerShell for users assigned to Privileged Identity Management (PIM), you can follow these steps:
Prerequisites
- Azure AD Module: Ensure you have the Azure AD PowerShell module installed.
- Permissions: Ensure you have the necessary permissions to assign licenses.
Install Azure AD Module: Install-Module AzureAD Connect to Azure AD: Connect-AzureAD Get PIM Users: $pimRole = Get-AzureADDirectoryRole | Where-Object { $_.DisplayName -eq "Privileged Role Administrator" } $pimUsers = Get-AzureADDirectoryRoleMember -ObjectId $pimRole.ObjectId Assign P2 License: $licenseSku = "ENTERPRISEPREMIUM" # Replace with the actual SKU ID for P2 license foreach ($user in $pimUsers) { Set-AzureADUserLicense -ObjectId $user.ObjectId -AssignedLicenses @{AddLicenses=$licenseSku} } Complete Script # Define variables $licenseSku = "ENTERPRISEPREMIUM" # Replace with the actual SKU ID for P2 license # Install Azure AD Module if not already installed if (-not (Get-Module -ListAvailable -Name AzureAD)) { Install-Module AzureAD -Force } # Connect to Azure AD Connect-AzureAD # Get PIM Users $pimRole = Get-AzureADDirectoryRole | Where-Object { $_.DisplayName -eq "Privileged Role Administrator" } $pimUsers = Get-AzureADDirectoryRoleMember -ObjectId $pimRole.ObjectId # Assign P2 License to each PIM user foreach ($user in $pimUsers) { Set-AzureADUserLicense -ObjectId $user.ObjectId -AssignedLicenses @{AddLicenses=$licenseSku} }
Steps to Run the Script
- Replace the placeholder
ENTERPRISEPREMIUM
with the actual SKU ID for the P2 license. - Save the script to a
.ps1
file. - Open PowerShell and run the script.
Documentation References
- Azure AD PowerShell Module
- Assign licenses to user accounts with PowerShell
- Privileged Identity Management (PIM) in Microsoft Entra ID
By using this script, you can automate the assignment of P2 licenses to users assigned to PIM roles.
Kindly accept answer if it helps
Please let me know if any further questions
Thanks
Deepanshu