如何在提示时将参数作为输入传递给 powershell 脚本?

How to pass a parameter as an input to powershell script when it prompts?

我是 Powershell 的新手。 “dt setup”是我试图自动化的命令,文件名为 dtSetupAutomation.ps1。此命令将提示我输入 UserMailId 和 UserName,然后我必须按回车键。我编码以获取 UserMailId 和 UserName 作为强制参数,但我不知道如何在命令提示时将其作为输入提供。 谁能帮帮我吗? dtSetupAutomation.ps1:

param(
    [Parameter(Mandatory=$True)]
    [string]$UserMailId,

    [Parameter(Mandatory=$True)]
    [Security.SecureString]$UserFullName
)
dt setup

“dt 设置”提示的内容:

脚本将在每行中以问号开头的每个提示停止,如下所示:

PS C:\> dt setup
 ====> Git Proxy configuration
? Allow devtool to manage your github proxy settings in the .gitconfig file? [? for help] (Y/n) Y
? Your email: [? for help] preethibe.91@gmail.com
? Your full name: [? for help] Preethi Palanisamy
 ====> Github token creation
? You already have a valid token. Skip token creation? (Y/n) Y
====== Git configuration ======
Git user.name: Preethi Palanisamy
Git user.email: preethibe.91@gmail.com
...
PS C:\>

这解决了我的问题:

$myshell = New-Object -com "Wscript.Shell"
.\dt.exe setup $myshell.sendkeys("Y") $myshell.sendkeys("{ENTER}") $myshell.sendkeys("preethix.palanisamy@intel.com") $myshell.sendkeys("{ENTER}") $myshell.sendkeys("{ENTER}")