How to execute a set of commands in high power powershell mode

I tried the following path to execute commands in admin 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

  • for the first call, it opens and successfully executes the command and closes the powershell admin instance. for the second call, he needs $ app information, which is not available, because it again opens a new administration window PS
  • I cannot run Get-AppxPackage -all in normal mode -all only -all mode -all required

tried 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 follow a set of instructions as above in high speed mode?

early

+6
source share
1 answer

The obvious way:

Open Powershell Console in Advanced Mode β†’ Right-click / exe and click Run as Administrator . Or, on the Start menu, type Powershell and press CTRL + SHIFT + ENTER

Then run the commands from this.

Or you can have the commands in the script file (.ps1) and call the script:

 start-process powershell -verb runas -argument script.ps1 

I would also like to mention that in the yout commands you do not need to store it in the $app , you can use something like:

 Get-AppxPackage -all| Where-Object{$_.Name-like "$ReleaseName"} | Remove-AppxPackage 
+5
source

Source: https://habr.com/ru/post/898803/


All Articles