[英]How can I execute scripts in a code created powershell shell that has Write-Host commands in it?
[英]How can I execute scripts in a code created powershell shell that has Host.Ui.prompt commands in it?
我有一個Powershell Commandlet,它可以根據條件從安全字符串中提示用戶。 現在,我想自動化此Commandlet的測試,為此我使用Powershell遠程運行空間來調用Commandlet。 當前,它因此錯誤而失敗。
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.
我該如何自動化?
聽起來您正在通過c#運行powershell。 您無法提示用戶輸入Powershell腳本的輸入。 您要么需要在腳本中預先提供必要的信息,要么從您的應用程序中提示輸入信息,然后將信息傳遞給powershell腳本。
正如ojk所提到的,最簡單的方法可能是使用powershell函數,然后通過代碼將必要的參數傳遞給它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.