Filtering users with specific license type

%3CLINGO-SUB%20id%3D%22lingo-sub-1293010%22%20slang%3D%22en-US%22%3EFiltering%20users%20with%20specific%20license%20type%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1293010%22%20slang%3D%22en-US%22%3E%3CP%3EHello.%20I%20have%20a%20.txt%20file%20with%20a%20list%20of%20users%20email%20addresses.%20I%20need%20to%20comb%20through%20that%20list%20of%20users%20and%20find%20which%20ones%20have%20the%20F3%20(old%20F1)%20license%20assigned%20to%20them%20from%20that%20list.%20The%20script%20I%20am%20running%20the%20script%20below%20which%20should%20only%20return%20users%20who%20%22DO%20NOT%22%20match%20E3..%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-notmatch%20%22SPE_E3%22%7D%7D%20%7C%20Select-Object%20UserPrincipalname%2Cislicensed%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EWhen%20I%20run%20the%20script%20it%20dumps%20our%20a%20.csv%20file%20and%20in%20the%20%22islicensed%22%20column%20it%20says%20TRUE%20for%20EVERY%20user.%20I%20was%20told%20that%20the%20-notmatch%20part%20should%20return%20only%20those%20users%20who%20are%20NOT%20E3%20but%20ever%20name%20comes%20back%20the%20same.%20Anyone%20know%20what%20I%20am%20doing%20wrong%3F%20Thanks%20in%20advance!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1293010%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFilter%20Office%20365%20User%20license%20type%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Contributor

Hello. I have a .txt file with a list of users email addresses. I need to comb through that list of users and find which ones have the F3 (old F1) license assigned to them from that list. The script I am running the script below which should only return users who "DO NOT" match E3..

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

When I run the script it dumps our a .csv file and in the "islicensed" column it says TRUE for EVERY user. I was told that the -notmatch part should return only those users who are NOT E3 but ever name comes back the same. Anyone know what I am doing wrong? Thanks in advance!

0 Replies