Finding opposite of Where-Object -match

Brass 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

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

@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.