简体   繁体   English

自动对 Powershell 中的提示回答“是”?

[英]Automatically answer “yes” to a prompt in Powershell?

New to PowerShell scripting. PowerShell 脚本的新功能。 I am trying to run the following code in PowerShell and make a script out of it:我正在尝试在 PowerShell 中运行以下代码并从中制作脚本:

md c:\\HWID
Set-Location c:\\HWID
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted -Force
Install-Script -Name Get-WindowsAutoPilotInfo -Force
Get-WindowsAutoPilotInfo.ps1 -OutputFile AutoPilotHWID.csv

Problem is I get multiple prompts to either say yes, yes to all, no, no to all, etc. I have tried ECHO, \force, -force, -Confirm:$false, yet I keep getting prompts.问题是我收到多个提示,要么说是,对所有人都是,不,对所有人都不是,等等。我已经尝试过 ECHO、\force、-force、-Confirm:$false,但我一直收到提示。 I am getting a prompt for NuGet provider.我收到 NuGet 提供商的提示。 What am I doing wrong?我究竟做错了什么?

Tested it on new win server 2019 VM.在新的 win 服务器 2019 VM 上对其进行了测试。

In case you have a new machine installed,to avoid interruption, run once from powershell terminal or insert into your script this line: Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted如果您安装了新机器,为避免中断,请从 powershell 终端运行一次或将此行插入您的脚本: Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted

mkdir c:\HWID2\
Set-Location c:\HWID2\

Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted # run once
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted -Force
Install-Script -Name Get-WindowsAutoPilotInfo -Force
...

Script does not prompt anymore.脚本不再提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM