Test-path not working properly

Apologies, I know I am posting a lot of topics today!

When trying to test a reg path in the new v4.0.4, it seems to not work properly.

I have tried as usual, creating a custom variable to test a reg entry.

$someinstall = test-path “some\reg\entry”

then an if statement to run the uninstall if detected.

This doesnt seem to work in the new psadt template. Log below:

I have also tried the below to no avail:

the new cmdlet Test-ADTRegistryValue also indicates true when running locally but in the install, acts like it isnt there.

the installation is 100% installed.

is this another bug in the new template?

Not much we can do with built-in PowerShell cmdlets: Test-Path (Microsoft.PowerShell.Management) - PowerShell | Microsoft Learn

With everything you’ve done there, you’ve basically bypassed everything PSADT has to offer; save for the logging. I’d do something like:

if ($installedApp = Get-ADTApplication -ProductCode '{00000000-0000-0000-0000-000000000000}')
{
    Uninstall-ADTApplication -InstalledApplication $installedApp
}

Even your log lines should be able to go as Get-ADTApplication will indicate if it found a match or not.

As for this line, you’re also hard-coding a check for the WOW6432Node key within the registry, which is fine(-ish), however won’t work if running Invoke-AppDeployToolkit.ps1 via a 32-bit PowerShell process (i.e. Intune with an Install line of something like powershell.exe -File Invoke-AppDeployToolkit.ps1). This is because the Intune Management Extension (sidecar) is a 32-bit process, so everything it spawns is 32-bit unless specified otherwise (i.e. %SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe -File Invoke-AppDeployToolkit.ps1`).

The issue I have is, the test-path is correct but when running in the tool, it does not seem to pick it up.

I see your point with the msi uninstall command but, how does that work if its a .exe without a product code? This is where we use simple test-path commands to look for install directories or reg keys.

What if the product code varies from your test and prod devices? It looks like an Acrobat code, they vary depending on the language installed etc. Using Get-ADTApplication -Name Acrobat will get you all apps that have Acrobat in the name.

The toolkit doesn’t have all this cool ■■■■ in it for no reason, it’s all there to make your life easier :fist_right::fist_left:.

1 Like

I would use that but this is what i am getting:


Of course that’s never going to work, and it’s not what I had in the example I gave you either. The output from Get-ADTApplication is an object, not a boolean. You should be testing that the variable isn’t null, not that it equals true.

You’re also doing your own uninstall command… See my example code again:

if ($installedApp = Get-ADTApplication -ProductCode '{00000000-0000-0000-0000-000000000000}')
{
    Uninstall-ADTApplication -InstalledApplication $installedApp
}
1 Like

Unfortunately, I am getting the same results:

If I run the command locally (the uninstall) it uninstalls fine but it isn’t detecting that the install is present still.

I still dont understand how a simple test-path to a reg entry does not come up as true in a if statement either. This method worked fine in previous versions.

Further example just for testing purposes:


That should just detect and run the uninstall.

I can’t help you anymore, man. I’ve already explained that Test-Path is built-in PowerShell command. If it’s not working, contact Microsoft.

Are you aware you have an extra single quote after the ++ and before the double quotes?
With the extra single quote the path is invalid so is correctly returning True
Without the extra single quote the path is valid so is correctly returning False

Also your logic looks wrong (in your ‘Notepad++’ sourced screen grab https://canada1.discourse-cdn.com/flex036/uploads/psappdeploytoolkit/original/2X/f/ff7867eba1165e7020e4affcd260f24146053134.png)…
This line:
if (!(Test-Path -Path $Notepad)){
is checking if $Notepad does not exist (because you are using not - i.e. !)
if you instead replaced that line as follows, the logic works:
if (Test-Path -Path $Notepad){

N.B. To help us help you in the future, if you need to post an example of your code on this forum, please use a code block (click on the </> toolbar button and it will create two lines of three escape characters or:
```

```

Then paste your code between these 2 lines, rather than pasting a screen grab), we can then easily copy and rework your code and post it back - rather than retyping it each time
Thanks

2 Likes

Thanks for getting back to me but, that also does not work. I have used many test-paths in v3 and they work fine but in v4, none seem to work correctly.

$notepadplusplus = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\Notepad++"
if (Test-Path -Path $notepadplusplus)

PS C:\WINDOWS\system32> Test-Path -Path $notepadplusplus
True

[Previous Application Detection] :: No previous versions to uninstall. Moving onto pre-requisite stage

Also, the new cmdlet to me, doesnt seem to function properly:

if(Get-ADTApplication -Name "Notepad++ (64-bit x64)"){
    Uninstall-ADTApplication -NameMatch Exact -ArgumentList "/S"} 

This also bypasses. I admit, my syntax maybe incorrect with that as I am trying to get my head around these new commands but, a basic test-path should work.

The same method works fine in v3 as mentioned.

After tearing my hair out for a day and feeling like I forgot how to powershell…

Something was throwing simple commands to wobble (not just test-path)… fixed those and below works fine.

$AdobeAcrobat2000620034 = (Get-ADTApplication -ProductCode '{AC76BA86-1033-FFFF-7760-0C0F074E4100}')
    $AcrobatReader = (Get-ADTApplication -ProductCode 'ac76ba86-1033-ff00-7760-bc15014ea700')

    if ($AdobeAcrobat2000620034 -ne $null){   
    Write-ADTLogEntry -Message "$($adtSession.Appvendor, $adtSession.Appname) 20.006.20034 detected. Uninstalling."
    Uninstall-ADTApplication -InstalledApplication $AdobeAcrobat2000620034 `
    -LogFileName "$($adtSession.Appvendor, $adtSession.Appname) 20.006.20034" `
    -ArgumentList '/QN /noreboot'}

     if ($AcrobatReader -ne $null){
    Write-ADTLogEntry -Message "$($adtSession.Appvendor) Reader. Uninstalling."
    Uninstall-ADTApplication -InstalledApplication $AcrobatReader `
    -LogFileName "$($adtSession.Appvendor) Reader" `
    -ArgumentList '/QN /noreboot'}
  
    else{
    Write-ADTLogEntry -Message "No previous versions to uninstall. Moving onto pre-requisite stage"}

Curly braces off the reader intentional as thats how they are in the apps registry would you believe. One big game with adobe.

1 Like

Or :poop:dobe as I prefer :wink:

Disclaimer:
This is the view of me personally, not that of my employer or that of those hosting this forum

3 Likes

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