Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Install-Module -Name AzureADPreview -RequiredVersion 2.0.0.1 -SkipPublisherCheck
Import-Module AzureADPreview -RequiredVersion 2.0.0.1
# Tenant Name
$tenantID = "mytenant.com.au"
# Admin User for the Tenant
$username = "admin@mytenant.com.au"
# Password for the Admin User
$password = '**********' | convertto-securestring -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential $Username,$password
#Connect to your AzureAD tenant
Connect-AzureAD -TenantId $tenantID -Credential $credentials -Confirm
# Removing a license
# Get the User
$user = get-azureaduser -ObjectId "user@mytenant.com.au"
# Assigned License
$user.AssignedLicenses
$lic = $user.AssignedLicenses.SkuId
# Remove the license
$body = @{
addLicenses = @()
removeLicenses= @($Lic)
}
Set-AzureADUserLicense -ObjectId "user@mytenant.com.au" -AssignedLicenses $body
# Read in the user to check license has been removed
$user = get-azureaduser -ObjectId "user@mytenant.com.au"
# Assigned Licenses should be empty
$user.AssignedLicenses
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.