简体   繁体   中英

Automatically answer “yes” to a prompt in Powershell?

New to PowerShell scripting. I am trying to run the following code in PowerShell and make a script out of it:

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. I am getting a prompt for NuGet provider. What am I doing wrong?

Tested it on new win server 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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