powershell - 提示时如何将参数作为输入传递给powershell脚本?
问题描述
我是PowerShell的新手。“dt setup”是我试图自动化的命令,文件名是 dtSetupAutomation.ps1。此命令将提示我输入 UserMailId 和 UserName,然后我必须按 Enter。我编码以获取 UserMailId 和 UserName 作为强制参数,但我不知道如何在命令提示时将其作为输入提供。谁能帮帮我吗?dtSetupAutomation.ps1:
param(
[Parameter(Mandatory=$True)]
[string]$UserMailId,
[Parameter(Mandatory=$True)]
[Security.SecureString]$UserFullName
)
dt setup
什么“dt setup”提示:
对于以问号开头的每一行中的每个提示,脚本都会停止,如下所示:
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}")
推荐阅读
- haskell - Haskell mulitline do 用于简单测试的语句
- python - 如何使子图的 Y 标签只出现一次?
- apache-spark - 如何在 PySpark 中编写条件正则表达式替换?
- node.js - 从快递中获取响应以做出反应
- javascript - 如何将具有相似键/值的数组中的对象转换为该数组中的数组
- django - DRF通过相关模型数据序列化
- python-3.x - 导入“用户”无法解析 Pylance(reportMissingImports)
- python - Python:如何将列表中的变量分配给字符串,然后将该字符串添加到不同的列表中?
- swift - 在 StoreKit 中使用多个产品标识符时 SwiftUI 应用程序冻结
- java - 如何在退出 JFrame 时停止 AudioSystem?