[Bug] Install-Module -Force prompts for user input when NuGet-anycpu.exe is not present
Steps to reproduce:
- Install WMF5 RTM on a fresh Windows 2012 R2 system
- Open an Administrator PS prompt and run "Install-Module Pester -Force"
Expected result: The -Force parameter causes the NuGet client to be installed without user intervention.
Actual result: The following message is displayed:
NuGet-anycpu.exe is required to continue.
PowerShellGet requires NuGet-anycpu.exe to interact with NuGet based galleries. NuGet-anycpu.exe must be available in
'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\Administrator\AppData\Local\PackageManagement\ProviderAssemblies'. For more information about NuGet provider,
see http://OneGet.org/NuGet.html. Do you want PowerShellGet to download NuGet-anycpu.exe now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"):
The MSDN documentation for $PSCmdlet.ShouldContinue (https://msdn.microsoft.com/en-us/library/ms568259%28v=vs.85%29.aspx) states "Cmdlets calling ShouldContinue should also implement a Force parameter that allows the cmdlet to bypass these calls. If this is not done, it will be difficult to use the cmdlet from scripts and noninteractive hosts." I'm trying to use Install-Module from an automated setup script on a fresh machine, and this prompt causes the script to hang.
Workaround: Before using Install-Module for the first time, run the following command to fetch NuGet-anycpu.exe (this is what Install-Module is doing internally):
PackageManagement\Get-PackageProvider -Name NuGet -Force
Understand the problem, will take a look at what we can do.
Install-PackageProvider NuGet -Force -scope CurrentUser;
install-module sqlserver -scope CurrentUser -Confirm:$False -force -SkipPublisherCheck
January 2020 and still no alternative... In my case the Nuget provider had to be updated before I could use Install-Module. To bypass any confirmation, first I ran "Install-PackageProvider -Name Nuget -Force".
-Confirm:$false worked for me in 2019 :P
I tried using the following flags, -Confirm:$true -Force and -Confirm:$false -Force, but it still ask for confirmation.
Luc Bergeron commented
Problem still there 2 years later...
Should install-module just be made to take the -ForceBootstap switch that automates that prompt for Install-Package ?
Issue raised: https://github.com/OneGet/oneget/issues/166
Please comment and add your voice to the discussion.
There is currently no solution or pull requests there.
Robert McLeod commented
The solution is fairly easy. All you need to do is pass the -Force:$Force to the lower layers. This is already done in a few places. It's just a mater of being consistent. If this was up on GitHub it'd be fixed in a matter of days.
Darren Rich commented
This happens on Win10 in Azure too.