SOLVED

Microsoft 365 E3 User Check

%3CLINGO-SUB%20id%3D%22lingo-sub-1275115%22%20slang%3D%22en-US%22%3EMicrosoft%20365%20E3%20User%20Check%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1275115%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20I%20am%20trying%20to%20adjust%20a%20script%20I%20have%20that%20checks%20if%20a%20user%20is%20licensed%20for%20E3%20in%20Microsoft%20365.%20The%20script%20I%20have%20below%20works%20by%20checking%20a%20list%20of%20users%20and%20seeing%20which%20ones%20are%20licensed%20for%20E3.%20However%20it%20does%20not%20tell%20me%20the%20users%20in%20that%20list%20that%20are%20NOT%20E3%20licensed.%20The%20.csv%20output%20looks%20like%20this....%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22charlie4872_0-1585833492241.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F181605iC7FA0EF9B6FB9EA0%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22charlie4872_0-1585833492241.png%22%20alt%3D%22charlie4872_0-1585833492241.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EMy%20question%20is%20can%20I%20have%20the%20%22IsLicensed%22%20column%20say%20%22False%22%20if%20the%20user%20does%20not%20have%20the%20E3%20license%3F%20Currently%20it%20just%20skips%20it%20and%20does%20not%20include%20it%20in%20the%20output.%20The%20script%20I%20am%20working%20with%20now%20is%20below.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EGet-content%20c%3A%5Ctemp%5Cusers.txt%20%7C%20foreach%20%7BGet-MsolUser%20-UserPrincipalName%20%24_%20%7C%20Where-Object%20%7B(%24_.licenses).AccountSkuId%20-match%20%22SPE_E3%22%7D%7D%20%7C%20Select-Object%20UserPrincipalname%2Cislicensed%20%7C%20Export-csv%20c%3A%5Ctemp%5CE3.csv%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EAny%20help%20is%20GREATLY%20appreciated%20I%20am%20on%20a%20timeline%20new%20to%20Powershell%20and%20cant%20find%20an%20answer%20in%20Google%20.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1275115%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMicrosoft%20365%20License%20Check%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1276519%22%20slang%3D%22en-US%22%3ERe%3A%20Microsoft%20365%20E3%20User%20Check%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1276519%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20for%20the%20reply%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F58%22%20target%3D%22_blank%22%3E%40Vasil%20Michev%3C%2FA%3E%26nbsp%3BFor%20some%20reason%20running%20the%20example%20you%20gave%20me%20and%20adjusting%20the%20SKUid%20exports%20a%20.csv%20and%20all%20users%20have%20the%20Islicensed%20column%20populated%20False.%20I%20then%20made%20a%20users.txt%20file%20with%20half%20of%20the%20list%20known%20F1%20users%20and%20half%20known%20E3%20users%20and%20the%20.csv%20output%20comes%20back%20with%20all%20users%20showing%20False%20in%20the%20Islicensed%20column.%20Any%20ideas%20what%20might%20be%20happening%3F%20And%20thanks%20again%20for%20your%20help!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1276180%22%20slang%3D%22en-US%22%3ERe%3A%20Microsoft%20365%20E3%20User%20Check%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1276180%22%20slang%3D%22en-US%22%3E%3CP%3EWell%20you%20are%20basically%20filtering%20all%20the%20users%20that%20do%20have%20the%20license%2C%20so%20everyone%20else%20is%20skipped.%20If%20you%20want%20to%20list%20the%20users%20that%20do%20not%20have%20the%20license%2C%20adjust%20the%20statement%20in%20the%20where%20clause%20to%20-notmatch.%20If%20you%20want%20both%20licensed%20and%20unlicensed%2C%20remove%20the%20clause%20altogether%20and%20simply%20populate%20the%20IsLicensed%20value%20accordingly%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-csharp%22%3E%3CCODE%3EGet-content%20c%3A%5Ctemp%5Cusers.txt%20%20%7C%20foreach%20%7B%20Get-MsolUser%20-UserPrincipalName%20%24_%20%7D%20%7C%20Select-Object%20UserPrincipalname%2C%40%7Bn%3D%22islicensed%22%3Be%3D%7B(%26amp%3B%7Bif%20(%24_.Licenses.AccountSkuId%20-match%20%22tenant%3AENTERPRISEPACK%22)%20%7B%22True%22%7D%20else%20%7B%22False%22%7D%7D)%7D%7D%7C%20Export-csv%20c%3A%5Ctemp%5CE3.csv%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CBLOCKQUOTE%3E%3CHR%20%2F%3E%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%26nbsp%3Bwhere%20I've%20complicated%20things%20a%20bit%20by%20doing%20everything%20in-line%2C%20but%20hopefully%20you%20get%20the%20idea.%20Make%20sure%20you%20enter%20the%20correct%20SKUid.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Contributor

Hello I am trying to adjust a script I have that checks if a user is licensed for E3 in Microsoft 365. The script I have below works by checking a list of users and seeing which ones are licensed for E3. However it does not tell me the users in that list that are NOT E3 licensed. The .csv output looks like this....

charlie4872_0-1585833492241.png

My question is can I have the "IsLicensed" column say "False" if the user does not have the E3 license? Currently it just skips it and does not include it in the output. The script I am working with now is below.

Get-content c:\temp\users.txt | foreach {Get-MsolUser -UserPrincipalName $_ | Where-Object {($_.licenses).AccountSkuId -match "SPE_E3"}} | Select-Object UserPrincipalname,islicensed | Export-csv c:\temp\E3.csv

Any help is GREATLY appreciated I am on a timeline new to Powershell and cant find an answer in Google .

 

Thanks!

3 Replies
Highlighted
Best Response confirmed by charlie4872 (Contributor)
Solution

Well you are basically filtering all the users that do have the license, so everyone else is skipped. If you want to list the users that do not have the license, adjust the statement in the where clause to -notmatch. If you want both licensed and unlicensed, remove the clause altogether and simply populate the IsLicensed value accordingly:

 

Get-content c:\temp\users.txt  | foreach { Get-MsolUser -UserPrincipalName $_ } | Select-Object UserPrincipalname,@{n="islicensed";e={(&{if ($_.Licenses.AccountSkuId -match "tenant:ENTERPRISEPACK") {"True"} else {"False"}})}}| Export-csv c:\temp\E3.csv

 where I've complicated things a bit by doing everything in-line, but hopefully you get the idea. Make sure you enter the correct SKUid.

Highlighted

Thanks for the reply @Vasil Michev For some reason running the example you gave me and adjusting the SKUid exports a .csv and all users have the Islicensed column populated False. I then made a users.txt file with half of the list known F1 users and half known E3 users and the .csv output comes back with all users showing False in the Islicensed column. Any ideas what might be happening? And thanks again for your help!

 

Highlighted

Hard to tell without specific examples, but then again I didn't spend much time testing the example :)