Finding opposite of Where-Object -match

%3CLINGO-SUB%20id%3D%22lingo-sub-1233987%22%20slang%3D%22en-US%22%3EFinding%20opposite%20of%20Where-Object%20-match%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1233987%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20been%20using%20a%20power%20shell%20script%20to%20find%20(from%20a%20list%20of%20users%20in%20a%20.txt%20file)%20who%20are%20licensed%20for%20a%20specific%20SKU%20in%20Office%20365.%20The%20script%20is.....%3C%2FP%3E%3CP%3E%26nbsp%3B%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-match%20%22MCOMEETADV%22%7D%7D%20%7C%20Select-Object%20UserPrincipalname%20%7C%20Export-csv%20c%3A%5Ctemp%5Clist.csv%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20question%20is%20how%20do%20I%20do%20the%20revers%20of%20this.%20I%20want%20to%20see%20what%20users%20from%20the%20same%20.txt%20file%20are%20NOT%20licensed%20for%20the%20specific%20SKU%20ID.%20I%20am%20fairly%20new%20to%20this%20and%20have%20tried%20a%20few%20things%20but%20am%20having%20no%20luck.%20Any%20help%20is%20appreciated.%3CBR%20%2F%3E%3CBR%20%2F%3EThanks!%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1233987%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1234400%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20opposite%20of%20Where-Object%20-match%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1234400%22%20slang%3D%22en-US%22%3E%3CP%3EDid%20you%20try%20-notmatch%3F%20%3A)%3C%2Fimg%3E%20Or%20you%20can%20prefix%20the%20entire%20condition%20with%20the%20-not%20operator.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1235094%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20opposite%20of%20Where-Object%20-match%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1235094%22%20slang%3D%22en-US%22%3E%3CP%3E%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%3BThanks%20for%20your%20reply%20I%20ran%20the%20script%20like%20below%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%24FormatEnumerationLimit%3D-1%0AGet-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%22MCOMEETADV%22%7D%7D%20%7C%20Select-Object%20UserPrincipalname%2Cislicensed%20%7C%20Export-csv%20c%3A%5Ctemp%5Clist.csv%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3Band%20it%20returned%20a%20list%20of%20users%20who%20are%20licensed.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Contributor

I have been using a power shell script to find (from a list of users in a .txt file) who are licensed for a specific SKU in Office 365. The script is.....

 

 

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

 

My question is how do I do the revers of this. I want to see what users from the same .txt file are NOT licensed for the specific SKU ID. I am fairly new to this and have tried a few things but am having no luck. Any help is appreciated.

Thanks! 

2 Replies
Highlighted

Did you try -notmatch? :) Or you can prefix the entire condition with the -not operator.

Highlighted

@Vasil Michev Thanks for your reply I ran the script like below

 

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

 and it returned a list of users who are licensed.