Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement