i have tried the below way to execute the commands in administrator mode.
PS>start-process powershell -verb runas $app = Get-AppxPackage -all| Where-Object{$_.Name-like "*$ReleaseName*"}
PS>start-process powershell -verb runas Remove-AppxPackage $app.PackageFullName
Get-AppxPackage -all
in normal mode -all
requires admin mode onlytried the below but no luck.
PS>start-process powershell -verb runas
{
$app = Get-AppxPackage | Where-Object{$_.Name-like "*$ReleaseName*"};
Remove-AppxPackage $app.PackageFullName
}
can someone suggest me how to execute set of instructions like above in powershell elevated mode?
thanks in advance
If you want to use the output of one command as the input of another command then you can use the pipe(|) operator.It is used extensively in Windows Powershell. ie. The output of the first command acts as input to the second command and the output of the second to another command is connected via a pipe.
To do so, type or paste powershell start-process powershell -verb runas into Command Prompt, and then hit Enter. A new elevated PowerShell window will appear.
Press Ctrl + Shift and double-click a shortcut to run as an elevated process.
The obvious way:
Open Powershell console in "elevated mode" -> Right click shortcut / exe and click Run as Administrator
. Or in start menu, type Powershell and hit CTRL + SHIFT + ENTER
Then run the commands from this.
Or you can have the commands in a script (.ps1 file) and invoke that script:
start-process powershell -verb runas -argument script.ps1
I would also like to mention that in yout commands, you don't have to store it in $app
, you can use something like:
Get-AppxPackage -all| Where-Object{$_.Name-like "$ReleaseName"} | Remove-AppxPackage
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With