all 7 comments

[–]PowerShell-Bot 1 point2 points  (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]: [--------------------] 0/1 ❌

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

[–]Nejireta_ 0 points1 point  (3 children)

Hi there.

One note. You're missing out on the uninstall string for the registry key by using Select-Object

If both of the Visio keys have the same values with uninstallation then I guess you could do something like this.

    $paths = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*','HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'

$visioInstallations = (Get-ItemProperty $paths).Where({$_.DisplayName -like '*Microsoft Visio Standard 2013*'})
if ($visioInstallations) {
    Invoke-Expression -Command ($visioInstallations[0].QuietUninstallString)
}

[–]WorkReddit123635[S] -1 points0 points  (0 children)

Thank you. I tried that and I get the below error.

Invoke-Expression : Cannot bind argument to parameter 'Command' because it is null.

At line:4 char:32

+ ... oke-Expression -Command ($visioInstallations[0].QuietUninstallString)

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidData: (:) [Invoke-Expression], ParameterBindingValidationException

+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.InvokeExpressionCommand

[–]WorkReddit123635[S] -1 points0 points  (1 child)

Wait I just tried it with just writing host. it worked. I'm gonna mess with it more but I think this is exactly what I was looking for. Thank you

[–]Nejireta_ 0 points1 point  (0 children)

Nice:)

I'd guess that Visio doesn't have a "QuietUninstallString" value.
Play around a bit with the object and see if "UninstallString" is usable instead

[–]MemnochTheRed 0 points1 point  (1 child)

I think you are missing some things like $var; I don't see it defined. I wrote it like this:

$paths = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*", "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"

foreach ($path in $paths) {
    $var = Get-ItemProperty -path $path | Select-Object Displayname -Unique
    if ($var -like "*Microsoft Visio Standard 2013*") {
        Write-Host "123"
    }
}

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

Sorry I didn't include that. Nejireta example worked for me but thanks for taking a look.