简体   繁体   English

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

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

what "dt setup" prompts: “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.

相关问题 如何将开关参数传递给另一个 PowerShell 脚本? - How to pass a switch parameter to another PowerShell script? 如何将多个Web作业作为参数传递给PowerShell脚本 - How to pass multiple webjobs as a parameter to the PowerShell script 如何将参数传递给jenkins管道中的powershell脚本 - How to pass a parameter to a powershell script in a jenkins pipeline 如何在 Powershell 脚本中将密码作为参数传递 - How to pass the password as parameter in Powershell script 通过cygwin从shell脚本运行时,如何将参数传递给powershell脚本? - how to pass parameter to a powershell script when running from a shell script through cygwin? 将多行参数传递给Powershell脚本 - Pass multiline parameter to powershell script 将带有 $ 的字符串传递给 Powershell 脚本参数 - Pass string with $ into Powershell script parameter 从Python调用时将参数传递给PowerShell脚本 - pass parameter to PowerShell script when calling from Python 两次运行脚本时,Powershell隐式远程会话会提示您输入密码 - Powershell Implicit Remoting Session prompts for password when running the script twice 如何将输入传递到CA NIMSOFT powerhell脚本中的powershell脚本? - How to pass a input to powershell script within a CA NIMSOFT powerhell script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM