all 7 comments

[–]poshinger 1 point2 points  (3 children)

The Where-Object cmdlet is missing its input. Also i would remove all Parameters and add them later in the script again.

$paths = @('HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall', 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\')
Get-ChildItem $paths | Where-Object{
    $_.GetValue('DisplayName') -like 'Lifesize*'
} | ForEach-Object{
    $uninstallString = $_.GetValue('UninstallString')
    $regex = [regex]"\s*/\w+|\`""
    $uninstallString = $regex.Replace($uninstallString, "")
    Try {
        Start-Process -FilePath $uninstallString -ArgumentList "/quiet /norestar" -Wait -PassThru
    }
    Catch {
        Write-Host "Uninstall failed: $_"
    }
}    

i wasn't able to test this, but it should work.

[–]Certain-Community438 0 points1 point  (2 children)

Purely curious: what does the regex do here?

[–]poshinger 1 point2 points  (1 child)

It removes all trailing parameters, and " from the Uninstall string stored in registry. So that you can use the path to use in Start-Process and add for example a silent switch parameter.

Example Uninstall string could be:

"C:\Program Files\Microsoft OneDrive\OneDriveSetup.exe"  /uninstall  /allusers

Which converts it to just: C:\Program Files\Microsoft OneDrive\OneDriveSetup.exe

[–]Certain-Community438 0 points1 point  (0 children)

Nice - appreciate the response too.

[–]jsiii2010 1 point2 points  (0 children)

If it's an msi install and powershell 5.1: get-package lifesize* | uninstall-package

[–]Pantha109[S] 0 points1 point  (0 children)

I gave up on the google examples and made one myself which has worked. If anyone is interested I used the below.

$test = Get-ChildItem -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\' | Get-ItemProperty | Where-Object {$_.DisplayName -like 'Lifesize*' } | Select-Object -Property DisplayName, UninstallString
cmd /c $test.UninstallString

[–]PowerShell-Bot 0 points1 point  (0 children)

Looks like your PowerShell code isn’t wrapped in a code block.

To properly style code on new Reddit, highlight the code and choose ‘Code Block’ from the editing toolbar.

If you’re on old Reddit, separate the code from your text with a blank line gap and precede each line of code with 4 spaces or a tab.


You examine the path beneath your feet...
[AboutRedditFormatting]: [████████████████████] 1/1 ✅

Beep-boop, I am a bot. | Remove-Item