0

Powershell outputs the string instead of executing command.

$apps = @()
$apps += Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" # 32 Bit
$apps += Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*"  

$apps365 = $apps | Where-Object {$_.DisplayName -Match "365" | Sort-Object DisplayName}



$uninPaths = @()
foreach ($item in $apps365) {
    $uninPaths += "& CMD /C "+$item.UninstallString
}

Invoke-Command -ScriptBlock{$uninPaths}
1
  • 1
    What makes you believe that the uninstall string requires to be run in cmd.exe? Usually the unistall string is a standard executable file which often accepts one or more arguments/parameters. They do not need to be exectuted in that specific CLI interface. Why not just try it directly in the PowerShell CLI interface, you're already using? Commented Apr 6, 2021 at 16:25

1 Answer 1

1

$uninPaths is just a string. To execute it like a command, you can feed it to Invoke-Expression:

Invoke-Expression -Command $uninPaths

Invoke-Command is generally used for running powershell commands on remote machines.

Sign up to request clarification or add additional context in comments.

1 Comment

Even with 'Invoke-Expression' it is only outputting the strings but not executing the commands.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.