Solved

How to remove office 365 license

Posted on 2016-09-09
6
51 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 15

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 14

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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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 14

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

This is my first article on Expert Exchange on the Manual Method of Exporting Office 365 Mailboxes to PST format by using the eDiscovery mechanism of Office. Hope you will enjoy the article.
Find out what you should include to make the best professional email signature for your organization.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

823 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