Created
November 13, 2014 16:31
-
-
Save guitarrapc/945408f9bd94e7a8f108 to your computer and use it in GitHub Desktop.
Remove Office365 User License
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
function Remove-Office365LicenseFromUser | |
{ | |
[CmdletBinding()] | |
param | |
( | |
[Parameter(Position = 0, Mandatory = 1, HelpMessage = "Pass MsolUser Objects.")] | |
[Microsoft.Online.Administration.User[]]$users | |
) | |
begin | |
{ | |
$ErrorActionPreference = "Stop" | |
# get sku | |
$accountSkuId = (Get-MsolAccountSku).AccountSkuId | |
} | |
process | |
{ | |
try | |
{ | |
# remove License to user | |
foreach ($user in $users) | |
{ | |
Write-Warning ("Removing Office365 License '{0}' from user '{1}'" -f $accountSkuId, $user.UserPrincipalName) | |
Set-MsolUserLicense -UserPrincipalName $user.UserPrincipalName -RemoveLicenses $accountSkuId | |
} | |
} | |
catch | |
{ | |
Write-Error $_ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment