Finding all F3 users from list with PowerShell

%3CLINGO-SUB%20id%3D%22lingo-sub-1292445%22%20slang%3D%22en-US%22%3EFinding%20all%20F3%20users%20from%20list%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1292445%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20I%20am%20trying%20to%20get%20a%20PS%20script%20to%20go%20through%20a%20list%20of%20users%20and%20filter%20it%20out%20so%20only%20the%20F3%20SKU%20users%20are%20listed%20as%20TRUE%20in%20the%20isLicensed%20column%20in%20the%20.csv%20output.%20The%20issue%20I%20am%20having%20is%20that%20when%20I%20run%20the%20script%20it%20is%20showing%20ALL%20users%20from%20the%20users.txt%20file%20as%20TRUE%20(meaning%20they%20should%20be%20F3)%20but%20when%20double%20checking%20random%20users%20they%20are%20show%20up%20as%20E3.%20The%20script%20I%20am%20using%20is%20below.%20I%20was%20told%20that%20using%20the%20-notmatch%20should%20work%20but%20no%20dice.%20Any%20ideas%20how%20I%20can%20get%20this%20to%20work%3F%20Many%20thanks!%3C%2FP%3E%3CP%3E%26nbsp%3B%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%20%7C%20Export-csv%20c%3A%5Ctemp%5CUsers_Without_E3.csv%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1292445%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFilter%20F3%20Users%20Powershell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1294798%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20all%20F3%20users%20from%20list%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1294798%22%20slang%3D%22en-US%22%3EHave%20you%20checked%20a%20user%20manually%20and%20verified%20that%20the%20E3%20SKU%20ID%20is%20SPE_E3%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1295371%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20all%20F3%20users%20from%20list%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1295371%22%20slang%3D%22en-US%22%3E%3CP%3EHello%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F186539%22%20target%3D%22_blank%22%3E%40Thijs%20Lecomte%3C%2FA%3E%26nbsp%3Band%20thanks%20for%20the%20reply.%20Yes%20I%20have%20verified%20the%20SKU%20id%20for%20the%20a%20known%20E3%20user%20and%20a%20known%20F3%20user%20in%20the%20list%20to%20verify%20the%20correct%20SKU%20id%20is%20being%20used%20in%20the%20script.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1302101%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20all%20F3%20users%20from%20list%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1302101%22%20slang%3D%22en-US%22%3EI%20just%20did%20some%20tests.%3CBR%20%2F%3EI%20think%20your%20issues%20might%20come%20from%20a%20few%20things%3A%3CBR%20%2F%3E%3CBR%20%2F%3E-%20Are%20you%20100%25%20sure%20about%20the%20AccountSkuID%2C%20because%20for%20me%20an%20E1%20has%20'STANDARDPACK'%20as%20it's%20accountskuid%3CBR%20%2F%3E-%20Is%20it%20possible%20users%20have%20multiple%20licenses%3F%20F3%2FE3%3CBR%20%2F%3E-%20Is%20the%20isLicensed%20field%20in%20your%20CSV%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1304751%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20all%20F3%20users%20from%20list%20with%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1304751%22%20slang%3D%22en-US%22%3E%3CP%3EHello%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F531473%22%20target%3D%22_blank%22%3E%40charlie4872%3C%2FA%3E%26nbsp%3B!%3CBR%20%2F%3EI've%20tried%20the%20same%20script%20and%20other%20variations%20of%20my%20own%20and%20I%20got%20it%20to%20work%20correct.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20it%20possible%20for%20you%20to%20share%20the%20Source%20file%20(%20users.txt%20)%20so%20I%20can%20see%20what%20fields%20you%20have%20and%20if%20something%20there%20might%20be%20wrong%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20maybe%20convert%20the%20txt%20to%20csv%20format%20and%20see%20if%20that%20works%20better%3F%26nbsp%3B%3CBR%20%2F%3ETry%20and%20work%20with%20variables%20instead%20of%20using%20so%20many%20pipes%20as%20well.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EI%20managed%20to%20do%20this%20with%20a%20few%20users%20with%20the%20following%20script%20(%20I%20used%20another%20SKU%20tho%20)%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EConnect-Msolservices%3CBR%20%2F%3E%24Users%20%3D%20Import-csv%20-Path%20%22C%3A%5CPath%5CUsers.csv%3CBR%20%2F%3E%24SKU%20%3D%20%22O365_BUSINESS_ESSENTIALS%22%3CBR%20%2F%3E%3CBR%20%2F%3EForeach%20(%24User%20in%20%24Users)%20%7B%3C%2FP%3E%3CP%3EGet-Msoluser%20-UserPrincipalName%20%24User.UserPrincipalName%20%7C%26nbsp%3BWhere-Object%20%7B(%24_.Licenses).accountSkuId%20-notcontains%20%24SKU%7D%20%7C%20Export-csv%20%22C%3A%5CPath%5CExport.csv%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELet%20me%20know%20how%20it%20goes%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKind%20RegardsOliwer%20Sj%C3%B6berg%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

Hello I am trying to get a PS script to go through a list of users and filter it out so only the F3 SKU users are listed as TRUE in the isLicensed column in the .csv output. The issue I am having is that when I run the script it is showing ALL users from the users.txt file as TRUE (meaning they should be F3) but when double checking random users they are show up as E3. The script I am using is below. I was told that using the -notmatch should work but no dice. Any ideas how I can get this to work? Many thanks!

 

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

 

 

4 Replies
Have you checked a user manually and verified that the E3 SKU ID is SPE_E3

Hello@Thijs Lecomte and thanks for the reply. Yes I have verified the SKU id for the a known E3 user and a known F3 user in the list to verify the correct SKU id is being used in the script.

 

Thanks.

I just did some tests.
I think your issues might come from a few things:

- Are you 100% sure about the AccountSkuID, because for me an E1 has 'STANDARDPACK' as it's accountskuid
- Is it possible users have multiple licenses? F3/E3
- Is the isLicensed field in your CSV?

Hello@charlie4872 !
I've tried the same script and other variations of my own and I got it to work correct. 

 

Is it possible for you to share the Source file ( users.txt ) so I can see what fields you have and if something there might be wrong? 

 

Also, maybe convert the txt to csv format and see if that works better? 
Try and work with variables instead of using so many pipes as well. 

I managed to do this with a few users with the following script ( I used another SKU tho ) 

 

Connect-Msolservices
$Users = Import-csv -Path "C:\Path\Users.csv
$SKU = "O365_BUSINESS_ESSENTIALS"

Foreach ($User in $Users) {

Get-Msoluser -UserPrincipalName $User.UserPrincipalName | Where-Object {($_.Licenses).accountSkuId -notcontains $SKU} | Export-csv "C:\Path\Export.csv"

 

Let me know how it goes 

 

Kind Regards
Oliwer Sjöberg