Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Uninstall Script - spaces in cmd-line arguement?

$
0
0

Good Morning all,

I have the following script I found on the Internet somewhere and it works great unless there are spaces in the path to the program, how do I make sure my variable is expanded and also that cmd treats the path as one long string?

$javaVer = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall  |

    Get-ItemProperty |

        Where-Object {$_.DisplayName -match "java" -or $_.Displayname -match "J2SE"} |

            Select-Object -Property DisplayName, UninstallString

 

ForEach ($ver in $javaVer) {

 

    If ($ver.UninstallString) {

 

        $uninst = $ver.UninstallString

        $uninst = $uninst.Replace('/I','/X ')

        & cmd -ArgumentList "/c $uninst /quiet /norestart"

        }

}

It is this line that fails if there are spaces in the path:

 & cmd -ArgumentList "/c $uninst /quiet /norestart"

Thanks for any help

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles