您的位置:首页 > 运维架构 > Shell

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

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
link|improve
this question
asked Oct
7 '11 at 0:19





Praveen
Jakkaraju

285

14% accept rate
feedback


1 Answer

activeoldestvotes

up
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


link|improve
this answer
edited Oct
7 '11 at 1:07

answered Oct
7 '11 at 0:35




manojlds

43.2k41547

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐