Last active
December 1, 2018 22:09
-
-
Save darrenjrobinson/3b85599503fc8299ff07710d24726063 to your computer and use it in GitHub Desktop.
Assign Office365 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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# License Body for RestAPI | |
$body = @{ | |
addLicenses = @(@{"skuId" = $LicenceToAdd}) | |
removeLicenses= @() | |
} | |
# Convert it to JSON | |
$postbody = $body | ConvertTo-Json | |
# License Users | |
foreach ($usertolicense in $unlicencedUsers){ | |
$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