powershell - 模拟 PowerShell 脚本中的选择选项
问题描述
我正在使用 PowerShell 脚本安装监视代理,该脚本要求我在运行脚本期间从一组选项中进行选择(幸运的是,我需要的选项是默认选项,因此在手动运行时,我只需按“Enter”并继续。
现在我正在使用下面的脚本,它显示了在最后一行之后选择的选项。如何模拟 Enter 按钮以便脚本成功完成。我尝试使用下面的 sendkeys(~) 代码,但它不起作用。
[Net.ServicePointManager]::SecurityProtocol = 'tls12, tls'
(New-Object System.Net.WebClient).DownloadFile("https://github.com/newrelic/newrelic-cli/releases/latest/download/NewRelicCLIInstaller.msi", "$env:TEMP\\NewRelicCLIInstaller.msi")
msiexec.exe /qn /i $env:TEMP\\NewRelicCLIInstaller.msi | Out-Null
$env:NEW_RELIC_API_KEY='NRAKABC'
$env:NEW_RELIC_ACCOUNT_ID='ABC'
# I Think it is prompting for input when userdata reaches this point
& 'C:\\Program Files\\New Relic\\New Relic CLI\\newrelic.exe' install --skipLoggingInstall
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('Administrator: Windows PowerShell')
Sleep 1
$wshell.SendKeys('~')
我将上面的脚本插入到厨师食谱中并从那里运行。知道如何解决这个问题。TIA
解决方案
所以解决方案是我们必须在安装新的 relic 基础设施代理后通过 -y。-y 当你通过它时假设都是肯定的。
无需使用发送键方法或任何其他方法来模拟输入。下面的代码工作正常。
[Net.ServicePointManager]::SecurityProtocol = 'tls12, tls'
(New-Object System.Net.WebClient).DownloadFile("https://github.com/newrelic/newrelic-cli/releases/latest/download/NewRelicCLIInstaller.msi", "$env:TEMP\\NewRelicCLIInstaller.msi")
msiexec.exe /qn /i $env:TEMP\\NewRelicCLIInstaller.msi | Out-Null
$env:NEW_RELIC_API_KEY='NRAKABC'
$env:NEW_RELIC_ACCOUNT_ID='ABC'
# I Think it is prompting for input when userdata reaches this point
& 'C:\\Program Files\\New Relic\\New Relic CLI\\newrelic.exe' install -y
--skipLoggingInstall
推荐阅读
- java - Java - 从对象列表中删除 null
- reactjs - 将函数传递给自定义钩子时如何修复useEffect中的无限循环
- mysql - MySQL 按子查询结果排序。空最后,> 0 为 1
- azure - 如何使用 deployIfNotExists 策略强制在 Azure 存储上配置删除保留?
- r - 用数值和 NA 折叠行的更好方法
- java - 由于 springboot 错误的审计名称列而导致架构无效
- git - Git 用 url 硬重置
- java - JPA:保存在数据库中后无法找到实体
- ssis - 从 Azure KeyVault 获取连接字符串以用于 ADF IS
- java - 如何在不同时间混合两个音频文件?