Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Created September 13, 2016 00:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrenjrobinson/7dac49ac831e1ae919148a59ead0f7d7 to your computer and use it in GitHub Desktop.
Save darrenjrobinson/7dac49ac831e1ae919148a59ead0f7d7 to your computer and use it in GitHub Desktop.
# 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