how to execute set of commands in elevated mode of powershell
2012-06-19 13:10
513 查看
http://stackoverflow.com/questions/7681920/how-to-execute-set-of-commands-in-elevated-mode-of-powershell
activeoldestvotes
4down votefavorite 1 share [g+]share [fb]share [tw] | 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 ' for the first call, it opens and executes the command successfully and closes the admin powershell instance. for the second call it requires $app information which is not available because it again opens a new PS admin window i can't execute "Get-AppxPackage -all" in normal mode "-all" requires admin mode only ' PS>start-process powershell -verb runas { $app = Get-AppxPackage | Where-Object{$_.Name-like "$ReleaseName"}; Remove-AppxPackage $app.PackageFullName }' tried this way but no luck. can someone suggest me how to execute set of instructions like above in powershell elevated mode? thanks in advance powershell
| ||
feedback |
1 Answer
activeoldestvotesup vote4down vote | 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
|
相关文章推荐
- How to set background image of a component in GWTEXT
- How to set Display Settings to EXTEND mode in Windows 7
- How to get and set the drawing order of layers in globe(获取并设置Globe图层的叠加次序:)
- How to delete a Enhancement SET of standard component in CRM
- How to set number of threads in OpenMP?
- How to get request_id of previous request in a request set?
- How to execute shell commands in C Part 1
- Here's an example that shows how to enumerate through the features of a selection set, returning the value of each field in the attribute table except for the geometry colum.
- How to boot ubuntu in text mode instead of graphical(X) mode
- How to customize authentication to my own set of tables in asp.net web api 2?
- How to set up and test a simple OLEDB Linked Server in Microsoft® SQL Server to allow retrieval of d
- [转]How to set the control word of FPU in delphi
- how to generate an analog output from a in-built pwm of Atmega 32AVR microcontrloller?
- How to change the language of oracle sqlplus from chinese to english in windows(如何将oracle sql plus中的中文变成英文版)
- How to create an OCM Response file to apply patch in silent mode - opatch silent (Doc ID 966023.1)
- How to correctly set application badge value in iOS 8?
- How To Set Up Database Replication In MySQL On Ubuntu
- How to set the sequence value while saving the record in OA Framework
- How to get HTML code of a WebElement in Selenium
- How to deal with large number of threads in clients