Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# Install the AzureAD Preview Module
# Install-Module -Name AzureADPreview -MinimumVersion -Force -SkipPublisherCheck
# Import the Module
Import-Module AzureADPreview -RequiredVersion
# Tenant Name
$tenantID = ""
# Admin User for the Tenant
$username = ""
# Password for the Admin User
$password = 'MyP@ssw0rd!' | convertto-securestring -AsPlainText -Force
# Credentials for the Admin User
$credentials = New-Object System.Management.Automation.PSCredential $Username,$password
#Connect to your AzureAD tenant
Connect-AzureAD -TenantId $tenantID -Credential $credentials
# Get the License SkuId from a similar user that we want to apply to the new user
$licensedUser = Get-AzureADUser -ObjectId ""
# Get the New User we want to apply the license too
$user = Get-AzureADUser -ObjectId ""
# check to see they have no license
# Create the new License Object
$license = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
$license.SkuId = $licensedUser.AssignedLicenses.SkuId
# Create the Licenses Table and add the license from above
$licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
$licenses.AddLicenses = $license
# Apply the license to the new user
Set-AzureADUserLicense -ObjectId $user.ObjectId -AssignedLicenses $licenses
# check to see license has applied
$user = Get-AzureADUser -ObjectId $user.ObjectId
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment