2017-06-29 192 views
0

我對Powershell完全陌生。在線查找腳本以更新Windows,並且想以管理員身份運行它。有從網絡共享啓動一個新的會話,並調用腳本的腳本:Powershell:以管理員身份運行腳本導致無限執行

PowerShell.exe -noprofile -command "&{Start-Process PowerShell -ArgumentList 
'-noprofile -file \\path\to\networkshare\00_WindowsUpdate.ps1' -Verb RunAs}" 

的問題是,它使運行該腳本和無限打開新的窗口。我搜索了互聯網,找不到任何特定於我的問題。如何運行我的腳本來調用Windows Update腳本一次,並防止它無限執行?

+0

什麼00_WindowsUpdate.ps1'的'的內容? –

+0

第1行:'導入模塊\ \路徑\ \ \ PSWindowsUpdate' 第2行:'Get-WUInstall -WindowsUpdate -IgnoreUserInput -AcceptAll -IgnoreReboot -Verbose | Out-File C:\ Windows \ Temp \ PSWindowsUpdate.log' – PatrykChristopher

回答

1

爲什麼使用PowerShell來調用PowerShell來運行PowerShell?

在.CMD:

RUNAS /noprofile /user:domain\user "powershell -ExecutionPolicy Bypass -Command '& \\Path\update.ps1'" 
+0

試過如果從cmd提示符下,仍然無限地執行並不斷打開新窗口。 – PatrykChristopher

+0

@PatrykChristopher這聽起來像是你試圖運行的腳本的錯誤。 – TheIncorrigible1

+0

這就是我猜測的。我已經嘗試了一個測試腳本,它爲Windows Update導入一個模塊,然後執行檢查更新歷史記錄的基本命令。難道它會不斷導入模塊? – PatrykChristopher

相關問題