如何以管理员身份运行powershell脚本?

时间:2013-09-25 11:22:52

标签: powershell

我有下面的静默卸载/等待/安装脚本,我需要向用户推送,但我需要编写脚本,以便它以管理员身份运行,我发现了一些脚本,但我不知道如何编写脚本,任何帮助表示赞赏。另外,我是否必须将管理员脚本放入两次? (即在卸载脚本的第一行然后在第二个安装脚本的行之前)或者只运行一次?

Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -eq "On-Screen Takeoff"} | foreach-

object -process {$_.Uninstall()}

Start-Sleep -Seconds 25

$arguments="/quiet"

Start-Process "\\davisconstruction.com\ROOT\Installs\OnCenter\OST\Testverion3906\ost3906.msi" $arguments

1 个答案:

答案 0 :(得分:3)

有两种方法:

  1. 您可以右键点击“开始” - > “Windows PowerShell模块”或“Windows PowerShell ISE”转到“开始” - > “管理工具” - > “Windows PowerShell模块”或“Windows PowerShell ISE”。 选择“以管理员身份运行”。 您在该窗口中运行的任何内容都将作为“管理员”。

  2. 将您的脚本运行为:

    Start-Process“$ psHome \ powershell.exe”-verb runas -ArgumentList“-file fullpathofthescript”

相关问题