Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created November 13, 2014 16:31
Show Gist options
  • Save guitarrapc/945408f9bd94e7a8f108 to your computer and use it in GitHub Desktop.
Save guitarrapc/945408f9bd94e7a8f108 to your computer and use it in GitHub Desktop.
Remove Office365 User License
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