Logic with Test-Path not executing

Hi, I hope you all have been well. I have been working within PSADT, but after numerous attempts to try and understand what’s going on, I believe I’m against a wall. What I am trying to accomplish is to test the path to a registrykey exists, and on $true it executes and uninstall. This doesn’t seem to do anything and it doesn’t fail, it simply runs and tells me it’s complete without making a change.

{ if (!(Test-Path -Path 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{BFBFDCC1-7657-4ED9-B5DE-F83AD449FDF}'))
{ Execute-MSI -Action Uninstall -Path '{BFBFDCC1-7657-4ED9-B5DE-F83AD449FDF}' -Parameters '/qn /norestart'} }

{ if (!(Test-Path -Path 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{AC3A8B99-F329-4128-87D9-BAA344426467}'))
{ Execute-MSI -Action Uninstall -Path '{AC3A8B99-F329-4128-87D9-BAA344426467}' -Parameters '/qn /norestart'} }

Thank you for any. I thought I was in the right direction with a test-path, but I must be missing something.

I wasn’t sure where to exactly post my question.

I think you have a logic problem. I fixed the spacing/indenting and the way I read your code:

If <regPath>\{GUID} does not exist {
  Uninstall MSI using {GUID} 
}

The way you wrote it, only when there is nothing to uninstall will it try to uninstall.
Remove the ! (aka -not operator) and it should work

1 Like

Thank you for taking the time to review this, and to address some formatting. I recognize that it wasn’t the cleanest way to port it over.

Thank you so much for the prompt and helpful feedback. This has addressed my issue and is totally working for me now.

I really appreciate this. I had confused myself, treating -not and ! independent from each other.

Thank you very much.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.