[英]How to pass a parameter as an input to powershell script when it prompts?
I am new to powershell.我是 PowerShell 的新手。 "dt setup" is the command which I am trying to automate and the file name is dtSetupAutomation.ps1.
“dt setup”是我试图自动化的命令,文件名为 dtSetupAutomation.ps1。 This command will prompt me for UserMailId and UserName followed by which I have to press enter.
此命令将提示我输入 UserMailId 和 UserName,然后我必须按 Enter。 I coded to get the UserMailId and UserName as mandatory parameters but i dont know how to provide it as input when the command prompts.
我编码以获取 UserMailId 和 UserName 作为必需参数,但我不知道如何在命令提示时将其作为输入提供。 Can anyone please help me?
谁能帮帮我吗? dtSetupAutomation.ps1:
dtSetupAutomation.ps1:
param(
[Parameter(Mandatory=$True)]
[string]$UserMailId,
[Parameter(Mandatory=$True)]
[Security.SecureString]$UserFullName
)
dt setup
The script will stop for every prompts in each line that starts with a question mark, as given below:脚本将针对每行中以问号开头的每个提示停止,如下所示:
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:\>
This resolved my issue:这解决了我的问题:
$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}")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.