使用 PowerShell 以管理员身份运行命令? [英] Running a command as Administrator using PowerShell?

查看:106
本文介绍了使用 PowerShell 以管理员身份运行命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您知道如果您是系统的管理员用户,只需右键单击一个批处理脚本并以管理员身份运行它,而无需输入管理员密码,您会如何?

You know how if you're the administrative user of a system and you can just right click say, a batch script and run it as Administrator without entering the administrator password?

我想知道如何使用 PowerShell 脚本执行此操作.我不想输入我的密码;我只想模仿右键单击以管理员身份运行方法.

I'm wondering how to do this with a PowerShell script. I do not want to have to enter my password; I just want to mimic the right-click Run As Administrator method.

我目前阅读的所有内容都要求您提供管理员密码.

Everything I read so far requires you to supply the administrator password.

推荐答案

如果当前控制台未提升,并且您尝试执行的操作需要提升权限,那么您可以使用以下命令启动 powershell以管理员身份运行选项:

If the current console is not elevated and the operation you're trying to do requires elevated privileges then you can start powershell with the Run as Administrator option :

PS> Start-Process powershell -Verb runAs

https://docs.microsoft.com/powershell/模块/Microsoft.PowerShell.Management/Start-Process

这篇关于使用 PowerShell 以管理员身份运行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆