11

I have added ChocolateyGet as a provider on Powershell so I can use it with PackageManagement (OneGet), it works but every package I try to install warns:

https://www.chocolatey.org is not a trusted package source

Then asks for confirmation. It also asks me if I agree to the license of the package.

I wanted to make a script to automatically install some packages, but I needed this script to be unattended, and it's not possible now because it asks those two previous questions.

Is there anyway to circumvent/automatically respond these confirmations? Like the y or yes command on Linux?

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
guilherme.oc97
  • 431
  • 1
  • 3
  • 13
  • 1
    I haven't tried, but `Install-Package` looks like it has both `-Force` and `-Confirm:$false` as possible parameters, have you tried either of those? – TessellatingHeckler Apr 23 '17 at 01:44
  • I have already tried `-Confirm`, and it doesn't work. In fact, if you use it, it won't even install your package. I'm not at home right now, but I'll try `-Force` later. – guilherme.oc97 Apr 23 '17 at 01:57
  • @TessellatingHeckler `-Force` works, skips both confirmation prompts. Thank you. – guilherme.oc97 Apr 23 '17 at 03:26

2 Answers2

24

You need to use -Force where there is a Force property available on any cmdlets, otherwise if there isn't but there is a confirm, you are able to use -Confirm:$False which acts the same as pressing Yes.

Be careful using this however as if you in fact didn't want to process the action...you don't get a second chance.

Random206
  • 757
  • 6
  • 19
  • 2
    Although it does bypass a confirmation prompt, the problem with `-Force` is that it forces a reinstall of the component even if it is already installed. – Frank Lesniak Dec 28 '18 at 04:57
2
choco feature enable -n allowGlobalConfirmation

will suppress license and other prompts during install.

Set-PackageSource -Name chocolatey -Trusted

will set package source as trusted.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
  • 1
    Instead you can use `-SkipPublisherCheck` option for Install-Module to allow untrusted package sources. – John Suit Sep 14 '18 at 15:28
  • 2
    @JohnSuit `-SkipPublisherCheck` is not for allowing untrusted packages, but for [installing newer versions of a module](https://learn.microsoft.com/en-us/powershell/module/powershellget/install-module?view=powershell-6). The only way to skip confirmation with untrusted modules is through `-Force`. – Nuno André Jun 01 '19 at 23:27