如何在包含Host.Ui.prompt命令的代码创建的powershell shell中执行脚本?

如何在包含Host.Ui.prompt命令的代码创建的powershell shell中执行脚本?,powershell,Powershell,我有一个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. T

我有一个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函数,然后通过代码将必要的参数传递给它。

这是您编写的cmdlet吗?看到一些代码会有所帮助。原则上,函数的所有输入都应通过参数进行。这使得自动化变得容易。