Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Last active December 1, 2018 22:09
Show Gist options
  • Save darrenjrobinson/84fb634286a726f19fab92643a93850c to your computer and use it in GitHub Desktop.
Save darrenjrobinson/84fb634286a726f19fab92643a93850c to your computer and use it in GitHub Desktop.
Remove Office 365 Licenses using Powershell and Graph API. Associated blog post can be found here https://blog.darrenjrobinson.com/adding-removing-user-office365-licences-using-powershell-and-the-azure-ad-graph-restapi/
# REMOVE License Body for RestAPI
$body = @{
addLicenses = @()
removeLicenses= @($LicenceToAdd)
}
# Convert it to JSON
$postbody = $body | ConvertTo-Json
# Remove License from Licenced Users
foreach ($usertolicense in $licensedUsers){
$AssignLicense = Invoke-RestMethod -Method Post -Headers @{
Authorization = $authenticationResult.CreateAuthorizationHeader()
'Content-Type' = "application/json"
} -body $postbody -Uri ("https://graph.windows.net/myorganization/users/$usertolicense`/assignLicense?api-version=1.6" -f $authenticationResult.TenantId)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment