Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to remove office 365 license

Posted on 2016-09-09
6
65 Views
Last Modified: 2016-09-09
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
0
Comment
Question by:glo-nsa
6 Comments
 
LVL 16

Expert Comment

by:Edward Pamias
ID: 41791378
There are a few ways to do this, one is to create a text file and put in the account names then run a powershell script which will handle the rest. See link below from Microsoft with the correct powershell scripts to run.

Click here.
0
 
LVL 15

Expert Comment

by:Todd Nelson
ID: 41791393
Take a look at these references.  The first is for assigning licenses but the foundation is there to remove licenses and license options as well.

https://oddytee.wordpress.com/2016/06/28/assign-subscription-licenses-and-license-options-to-office-365-users/

https://oddytee.wordpress.com/2015/06/10/references-add-office-365-licenses-with-powershell/

Let us know.
0
 

Author Comment

by:glo-nsa
ID: 41791502
The syntax for removing I have down. What I am needing is the filter for only users that already have the named license.

I think there should be a filter condition on the back of this statement:
$x = Get-MsolUser -All  | where {$_.isLicensed -eq $true}

Thoughts?
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 40

Accepted Solution

by:
Vasil Michev (MVP) earned 500 total points
ID: 41791512
You can filter by license SKU via:

Get-MsolUser -All | ? {$_.Licenses.AccountSkuId -eq "tenant:PROJECTCLIENT_GOV"}

Open in new window


or whatever the SKU is.
0
 
LVL 15

Expert Comment

by:Todd Nelson
ID: 41791518
You can do that to get all of the users that are assigned a license.  Have you tried that?
0
 

Author Closing Comment

by:glo-nsa
ID: 41791533
Perfect! Concise and with relevant example.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Read this checklist to learn more about the 15 things you should never include in an email signature.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question