'How to execute a string in a variable in powershell

I have the following string

"C:\ProgramData\Package Cache{6b95042e-f763-4850-9136-d004dd0d0a9b}\AzInfoProtection.exe" /uninstall

I need to execute the above string as below

First-line

cd C:\ProgramData\Package Cache\{6b95042e-f763-4850-9136-d004dd0d0a9b}

The second line (note there is no exe)

AzInfoProtection /uninstall

Variables are generally executed like below in PowerShell

Invoke-Expression $cmd

But how to split the above string into multiple lines for execution. Then I need to remove the quote and then exe.



Solution 1:[1]

To run the string you can pipe it to cmd to run it using:

$commandString | cmd

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Elikill58