2016-04-22 144 views
0

我是一個管理員和學習腳本,但試圖創建一個腳本來打開多個程序作爲另一個用戶(我的管理員密碼)目錄名稱是無效的 - PowerShell腳本

下面的腳本運行時,運行良好PowerShell ISE中,但將無法正常運行時,右擊並選擇"run with powershell"

Start-Process -FilePath "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -Credential "domain\userid" 

在運行時會提示輸入密碼,但並不帶來了谷歌瀏覽器。從Powershell ISE運行時,它工作正常,從Powershell.exe(而不是ISE環境)運行腳本時,我得到錯誤"The directory name is invalid"

+0

無法重現的問題我的Windows Server 2012上使用PowerShell 4.0。這個命令在我的powershell控制檯和powershell ISE –

+0

中是一樣的。如果運行'start-process -filepath c:\ asdfasdf \ asdf.exe',返回的錯誤是*「由於錯誤,此命令無法運行:系統找不到指定的文件「*,not *」目錄名稱無效「*。我想這是在配置上下文菜單中的「使用PowerShell運行」,也許它有一個無效的PowerShell解釋器路徑,或者PowerShell.exe進程無法讀取腳本路徑(但我無法在一些快速測試中再現這個錯誤)。錯誤是PowerShell異常還是資源管理器對話框? – TessellatingHeckler

+0

如果您要以這種方式從運行菜單或cmd提示執行它,該怎麼辦?相同的目錄名稱是無效的消息? 'powershell.exe -nop「C:\你的script.ps1的路徑」' – ssaviers

回答

1

添加工作目錄:

Start-Process ` 
    -FilePath "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" ` 
    -Credential "domain\userid" ` 
    -WorkingDirectory "C:\Program Files (x86)\Google\Chrome\Application\"