Skip Ribbon Commands
Skip to main content

Title

I feel like an idiot.

Body

My head hit the desk when I realised I'd spent fifteen minutes trying to remove licenses that had already been removed.

For reference, no text parsing, just use where-object to compare the contents of two arrays of skuids:

$SKUsToAdd = @('contoso:EXCHANGESTANDARD','contoso:O365_BUSINESS_PREMIUM')
$Users = @('joe@contoso.com','jane@contoso.com')

Foreach ($User in $Users) {
   $CurrentSKUs = (Get-MsolUser -UserPrincipalName $User).Licenses.AccountSKUID
   $NewSKUs = $SKUsToAdd | where {$CurrentSKUs -NotContains $_}

   If ($NewSKUs) {
       Set-MSOLUserLicense -UserPrincipalName $User -AddLicenses $NewSKUs
   }

}



Today's date

8/22/2017

Twitter

 
Approval Status Pending
 

Attachments

Created at 8/22/2017 1:15 AM by  
Last modified at 8/22/2017 1:15 AM by