'Filtering packages by their name from list out of file

I am trying to read program names from a file to filter out the installed ones. For reading the file I got: $file = Get-Content "C:\Users\testuser\Desktop\Test.txt"
Then I try to filter packages by their name which isnt working, what I tried:

Get-AppxPackage | Where-Object -Property Name -notin $file | select Name, IsFramework

or

Get-AppxPackage | Where-Object { $_.Name -notin $file } | select Name, IsFramework

I cannot use any .Net statements, how can I solve this?

Edit: Here is my file's content:

Microsoft.BioEnrollment Microsoft.AAD.BrokerPlugin Microsoft.Windows.CloudExperienceHost Microsoft.Windows.ShellExperienceHost windows.immersivecontrolpanel Microsoft.Windows.Cortana Microsoft.AccountsControl Microsoft.LockApp


Solution 1:[1]

Just to recap from David Brabant, the following worked for askingQuestions:

Get-AppxPackage | ?{ $file.Contains($_.Name) } | select Name, IsFramework

This works great and is probably one of the best ways to do this.


This didn't work for me for all applications, so here's another take at filtering the list. :)

Matching Name:

Get-WmiObject -Class Win32_Product | Where-Object {$_.name -Like "appName"}

Not Matching Name:

Get-WmiObject -Class Win32_Product | Where-Object {$_.name -NotMatch "appName"}

Note that using Where-Object is not case sensitive but looks for exact match. On the flip side, you can also use wildcards.

but to filter by file, you could do something like:

[string[]]$List = (Get-Content -Path 'C:\test.txt') -replace ' ',"`r`n"
 foreach ($ProgramName in $List)
 {
 Get-WmiObject -Class Win32_Product | Where-Object {$_.name -Like $ProgramName}
 }

Note that -replace ' ',"rn" is only necessary for spaces between application names. You can just remove this and have each application on a new line. Also note that this could possibly produce duplicates.

Wildcard Example:

Get-WmiObject -Class Win32_Product | Where-Object {$_.name -Like "*adobe*"}

Cheers!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CodeNeedsCoffee