O365 PowerShell: Find users that have specific product license services enabled RRS feed

  • Question

  • I'm hoping this is the right place to post this. I have posted here too but have always had better results from TechNet forums.

    I'm using the following article View account license and service details with Office 365 PowerShell to try to obtain a report of all users in our tenant where the product license Office 365 Enterprise E3 is assigned but with only the the service Exchange Online (Plan 2) enabled.

    The article suggests this can be done with a command similar to the following:

    Get-MsolUser | 
    Where-Object {
       $_.isLicensed -eq $true 
       -and $_.Licenses[0].ServiceStatus[16].ProvisioningStatus -eq "Enabled"

    In my case [16] being the 17th service in the list for Office 365 Enterprise E3.

    There are additional lines before to set the criteria for the rest of the services as "disabled" but hopefully you get the idea however, the article also states that the index number reflects the order that the product license and service plan appears when running either of the below script blocks:


    Get-MsolUser -UserPrincipalName  | Format-List DisplayName,Licenses


    Get-MsolUser -UserPrincipalName

    The issue with the above is that many users have different combinations of plans enabled so for some, a license index of [0] would refer to a different service plan. e.g. user1 has Visio Online Plan 2 and Office 365 Enterprise E3 product licenses assigned but user2 only Office 365 Enterprise E3. Index [0] in this instance would be different making the initial script block useless in finding all users with a specific service enabled regardless of combination of product licenses assigned.

    Am I missing something here?

    Wednesday, February 14, 2018 10:01 AM


All replies

  • We cannot help you with articles found on the Internet.  Please ask the author of the article for help if the instructions are unclear or wrong.

    You will also need to learn PowerShell before trying to understand or write scripts from online articles.

    The following will help you get started.  Check the Gallery for scripts that can do what you ask.

    Please carefully review the following links to set your expectation of technical forums.

    This Forum is for Scripting Question Rather than script requests

    Script Gallery.

    Learn PowerShell  

    Script requests


    Wednesday, February 14, 2018 10:09 AM
  • The article is simply a MS document/guide on how to it's possible to obtain the information required using examples. The idea is to use this as a basis and expand on it to grab the information unique to my environment. Surely the idea is to learn from these and write a relevant script no? This is me now asking for help on something I've put together not me asking you to fix an existing one or create me one.

    I do have a fair amount of PowerShell scripting experience already and do understand the script, however, don't know everything which is why I'm after some advice. So far I haven't found anything that explains this further or how to address my issue. Also I've received help here for similar scenarios in the past which is why I came back....


    • Edited by JShand Wednesday, February 14, 2018 3:17 PM
    Wednesday, February 14, 2018 1:01 PM
  • To match  product license you would use the operators "-in" or "-contains" to test the license SKU with the list.

    if($mylicense -in $user.Licenses){ ...


    Wednesday, February 14, 2018 6:17 PM
  • I've been directed to the extremely useful tool Office 365 License Reporting and Management Tool -Assign Remove Licenses in Bulk in the Microsoft Community forums which I mentioned I posted to in my first post.

    This gives me the information I need without needing to script it so looking good. 

    • Marked as answer by JShand Thursday, February 15, 2018 5:04 PM
    Thursday, February 15, 2018 5:03 PM
  • For O365  issues you should always start your quest in the O365 community forums.   MS is adding and extending tools ervy month and most regular management functions can now be done without scripting ot with O365 workflows.  Occasionally things might be easier with a script but the fundamentaly rules of how to do this will be in the individual product forums (Exchange/SharePoint ...) or in the O365 communities.

    When you have a specific issue about how to use PowerShell with a solution you understand then this forum would ba a good choice to ask that specific kind of question.

    Always check the Gallery and the PowerShellGet repository.


    find-module *o365*

    find-module *mso*


    Thursday, February 15, 2018 5:20 PM
  • I'm guessing you're referring to Your community for best practices and the latest news on Office 365. Thanks for the advice, however, as mentioned, I understood the script and what it was trying to achieve but there's a flaw in it if licenses are not assigned in the same order for everyone. This script doesn't accommodate that scenario so needed advice on how to address this. I'm really not sure how that's not considered a good choice for a question to ask here.....

    Tuesday, February 20, 2018 9:34 AM
  • I posted the answer to your question.  Here it is again.  To find something in a collection do this:

    if($mylicense -in $user.Licenses){ ...

    or any variation of this that uses the "-in" operator to test against a collection.

    PS>$a = 1,2,3,4,5
    PS>3 -in $a
    PS>6 -in $a

    And no I am not referring to that forum.  The O365 community forums are available from the help menu of your portal.  There are many and they are specific to each area of O365.


    Tuesday, February 20, 2018 9:47 AM
  • Ah yes, I have a bookmark to those forums too but as mentioned, generally always got the relevant help I needed here and based on searches for similar questions asked by others.

    The issue here isn't that I'm trying to enumerate a simply array but rather I need to find users with a specific service plan that shows a specific string. Finding the initial service isn't the problem and using an array instead will not address this, it's finding this service that matches a specific status.

    As mentioned, the tool linked provides the information I need so it's all gravy at the moment but is something I'd like to script out ultimately as is will be more targeted than the tool can be.


    Thursday, February 22, 2018 9:59 AM
  • Hello JShand,

    I found nice article here:

    I hope this is what you need.



    Wednesday, July 17, 2019 3:03 AM