繁体   English   中英

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

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM