Home > Software engineering >  is there a way to check if a program is installed just by filename in powershell?
is there a way to check if a program is installed just by filename in powershell?

Time:11-23

I am trying to create a powershell script to auto install all .msi and .exe files silently in a directory. However while doing this i want to check if any of the programs are already installed.

I know i can get all installed files in the system like below

$32bit_softwares = Get-ItemProperty HKLM:\SOFTWARE\wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* |
                        Select-Object DisplayName,DisplayVersion,Publisher,InstallDate
                        
$64bit_softwares = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* |
                        Select-Object DisplayName,DisplayVersion,Publisher,InstallDate
$all_softwares = $32bit_softwares $64bit_softwares

    

and i can get the filenames of the files in the directory like below:

$directoryRead = Read-Host -Prompt "enter directory"
$fileNames = Get-ChildItem $directory -Recurse -include *.exe,*.msi | ForEach-Object {$_.name}

How can i compare these 2 in a loop? like

$all_softwares.DisplayName -like "$softwareName*"

I am not sure a like filter above will do the job as filenames will be like examplename.exe

Thanks in advance.

CodePudding user response:

So the problem that I see and I think you are asking about is that the installer filename will be different than the software name you pull out of the Registry. With the difference it will be hard to match up exactly.

Is the set of MSI's and/or EXE's (the installers) a known, static set? Would it be possible to setup a hash table (dictionary) mapping between the Registry name and the installer name?

This would make matching exactly while looping through the installers and doing a .Contains on the array from the Registry easier.

  • Related