如何在powershell的提升模式下执行命令集
我尝试了以下方法在管理员模式下执行命令。
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
- 对于第一次调用,它成功打开并执行命令并关闭管理 powershell 实例。对于第二次调用,它需要 $app 信息,但该信息不可用,因为它再次打开一个新的 PS 管理窗口
- 我无法在正常模式下执行
Get-AppxPackage -all
-all
> 需要管理员模式只
尝试了以下但没有运气。
PS>start-process powershell -verb runas
{
$app = Get-AppxPackage | Where-Object{$_.Name-like "*$ReleaseName*"};
Remove-AppxPackage $app.PackageFullName
}
有人可以建议我如何在 powershell 提升模式下执行上述指令集吗?
提前致谢
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
tried 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显而易见的方法:
以“提升模式”打开 Powershell 控制台 ->右键单击快捷方式/exe,然后单击
以管理员身份运行
。或者在开始菜单中,键入 Powershell 并按 CTRL + SHIFT + ENTER然后从中运行命令。
或者,您可以将命令放在脚本(.ps1 文件)中并调用该脚本:
我还想提一下,在 yout 命令中,您不必将其存储在
$app
中,您可以可以使用类似的东西: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 + ENTERThen run the commands from this.
Or you can have the commands in a script (.ps1 file) and invoke that script:
I would also like to mention that in yout commands, you don't have to store it in
$app
, you can use something like: