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