Avatar of glo-nsa
glo-nsa
Flag for United States of America

asked on 

How to remove office 365 license

Hello Experts,

I need to remove the licenses from my o365 users nightly. (I'll tell why if asked.)
I was trying to use this:
$x = Get-MsolUser -All  | where {$_.isLicensed -eq $true}; $x | foreach {Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -RemoveLicenses "tenant:PROJECTCLIENT_GOV"}

Which should work, but looks ugly failing on 700 accounts and succeeding on the 35 that actually have licenses.
How can I change this statement to return only account licensed to use tenant:PROJECTCLIENT_GOV?

Thanks,
Keith
Microsoft 365Powershell

Avatar of undefined
Last Comment
glo-nsa

8/22/2022 - Mon