2014-10-07 14 views
0

我有一個Powershell Commandlet,它根據條件從安全字符串中提示用戶。現在我想自動執行此命令行的測試,爲此我使用Powershell遠程運行空間來調用命令行開關。目前它失敗並出現此錯誤。如何在創建了Host.Ui.prompt命令的代碼創建的powershell shell中執行腳本?

Write-Host : A command that prompts the user failed because the host program or the command type  does not support user interaction. Try a host program that supports user interaction, such as the Windows PowerShell Console or Windows PowerShell ISE, and remove prompt-related commands from command types that do not support user interaction, such as Windows PowerShell workflows. 

我該如何實現自動化?

+0

此cmdlet是您寫的東西嗎?這將有助於看到一些代碼。原則上,所有對函數的輸入都應該通過參數。這使它很容易自動化。 – ojk 2014-10-07 10:24:44

回答

0

這聽起來像你正在通過c#運行powershell。您不能提示用戶從powershell腳本輸入。您需要預先在腳本中提供必要的信息,或者從應用程序提示輸入信息,然後將信息傳遞給powershell腳本。

正如ojk提到的最簡單的方法來完成這可能是使用PowerShell功能,然後通過代碼傳遞必要的參數。

相關問題