我需要從另一個PowerShell腳本爲不同的用戶和隱藏的窗口中運行PowerShell腳本。運行PowerShell腳本爲不同的用戶和隱藏的窗口從另一個PowerShell腳本
什麼我到目前爲止有:
Start-Process powershell '& C:\test.ps1' -WindowStyle Hidden -Credential $cred
其中$cred
是PSCredential
對象。該test.ps1
腳本是用於測試目的與Remove-Item
一行。由於我仍然可以看到文件沒有被刪除,我可以告訴腳本沒有運行。
編輯
我的初衷是爲了運行regedit劇本,但當時我正在執行Start-Job
答案(下)我得到這個錯誤:
Start-Job : The value of the FilePath parameter must be a Windows PowerShell script file. Enter th
e path to a file with a .ps1 file name extension and try the command again.
因爲這個問題是如此普遍,我想指出的是,一個'PSCredential'對象使用此技術的用戶是「管理員」的成員不會運行提升。你必須爲此使用'Runas'動詞。 (我不知道這是否是你的意圖或沒有。) –