0
$remove = @('microsoft*','visual*')

Get-WmiObject -Class Win32_Product -ComputerName $CompName | Where-Object {
    $f = $_.name -notcontains $remove
    $remove | Where-Object { $f.($_) }
} | Format-Wide -Property Name -Column 1    

I'm not sure how to nest this properly so that I can filter out the everything in $remove and display the rest of the programs. I'm not getting any errors it will wait for about 10 seconds then continue to the PS prompt.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • To confirm, are you trying to remove anything that has a name starting with Microsoft or Visual ? – Gareth Lyons Feb 01 '18 at 19:31
  • yes sir, but that array is going to grow. I need to filter out programs that I don't need to install. I was using Microsoft and visual just for testing. – AnimalChubs Feb 01 '18 at 19:36
  • What is `$f = $_.name -notcontains $remove` and `$f.($_)` supposed to accomplish? Please read up on how [PowerShell operators](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-3.0) work. You need something like `$n = $_.Name; -not ($remove | ? {$n -like $_})`. – Ansgar Wiechers Feb 01 '18 at 20:01

1 Answers1

0

notcontains looks for exact matches so won't help you here. Simplest way is probably this, although your regex may get quite nasty if there's lots to exclude:

get-wmiobject -class Win32_Product -ComputerName $CompName | Where-Object {

$_.name -notmatch "^(Microsoft|Visual)."

} | Format-Wide -Property Name -Column 1
Gareth Lyons
  • 1,942
  • 12
  • 14