Hello - I’m trying to pull a list of software installed on multiple computers. I’ve part of my script block below.
Everything is working as I would expect it except for the “if ($SWDisplayName -notmatch $UnwantedSW){…”
No matter what I have tried to get the -Match or -NotMatch operator to work it won’t place nice.
If anyone has any input please let me know.
# Place holder for when this runs in the scriptblock for invoke command
$Computer= "Bob"
#List of SW titles that I'm looking to filter out
$UnwantedSWTitles= "Microsoft office","sql","exchange",".NET","C++","VMware","7-zip","Report Viewer","Sharepoint","Citrix","IIS","Silverlight","NSClient","Visual Studio","Adobe","Java","Google","Firefox","PDF","Apache"
#Converts the UnwantedSWTitles string to a regex variable
[regex]$UnwantedSW = '^(' + (($UnwantedSWTitles|foreach {[regex]::escape($_)}) –join '|') + ')$'
#Gets a list of all x86 based software installed on the system
$SWx86 = Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | Get-ItemProperty
#Filters through each software title
Foreach ($SW in $SWx86){
#Grabs the SW name (I know it's the old way of doing it but making sure it v2 compatible)
$SWDisplayName = $SW | Select-Object -ExpandProperty displayname -ErrorAction SilentlyContinue
#Checks to see if the software's display name is listed in the UnwantedSW list
#This is what I'm having trouble filtering on
if ($SWDisplayName -notmatch $UnwantedSW){
#Pulls the info from the SW title if its display name does NOT contain any words from within the $UnwantedSWTitles
$Prop = @{ComputerName = $Computer;
SWDisplayName = $SW| Select-Object -ExpandProperty Displayname -ErrorAction SilentlyContinue;
SWVendor = $SW | Select-Object -ExpandProperty Publisher -ErrorAction SilentlyContinue;
SWVersion = $SW | Select-Object -ExpandProperty DisplayVersion -ErrorAction SilentlyContinue;
SWInstallDate = $SW| Select-Object -ExpandProperty InstallDate -ErrorAction SilentlyContinue}
Write-Output $Prop
}
}