I wrote a script to check for the file path for firefox in Windows x64 Host Key. It has a try catch block that has a fully qualified error id in the brackets.
Despite the error message being the same that is in the code, it does not catch the error.
$program = "FireFox"
$filepath = "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
$FPF = $filepath + "\" + $program
try { Get-ChildItem $FPF}
catch [PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand] {
if ($_.Exception.Message -match "Get-ChildItem : Cannot find path*") {
Write-Host "false"}
}
The full error that comes out is
Get-ChildItem : Cannot find path 'HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\FireFox' because it does not exist.
At line:7 char:7
+ try { Get-ChildItem $FPF}
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (HKEY_LOCAL_MACH...install\FireFox:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId :PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
What could could be the issue?
tryis for) and a non terminating error (whatget-childitemit doing). either way you should be usingif(Test-Path $FPF)for things like this.Test-Pathmust have been what I needed to do originally. Thank you