Automating install of module

Hello
I am looking to run the following command without user input and automacally accept
Install-Module -Name PSWindowsUpdate -Force
The issue is it requires you to press Y or A to accept,


PS C:\WINDOWS\system32> Install-Module -Name PSWindowsUpdate -Force NuGet provider is required to continue
PowerShellGet requires NuGet provider version ‘2.8.5.201’ or newer to interact with NuGet-based repositories. The NuGet
provider must be available in ‘C:\Program Files\PackageManagement\ProviderAssemblies’ or
‘C:\Users\dumb.dumb\AppData\Local\PackageManagement\ProviderAssemblies’. You can also install the NuGet provider by
running ‘Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force’. Do you want PowerShellGet to install
and import the NuGet provider now?
[Y] Yes [N] No [S] Suspend [?] Help (default is “Y”):


I found -Confirm but could not figure out how to add that to the command so when i run it it will automatically install the module and not require user input something like

Install-Module -Name PSWindowsUpdate -Force -Confirm “Y”

Thank you for any input.

Dennis

Hello Dennis, welcome to the forum. To use -Confirm add $false like this -Confirm:$false. However, the output you are trying to suppress is coming from Install-PackageProvider. I use this little bit of code to ensure no interruptions.

$version = "2.8.5.208"

Write-Verbose "Verifying NuGet $version or later is installed"

$nuget = Get-PackageProvider -Name NuGet -ListAvailable -ErrorAction SilentlyContinue |
                Sort-Object -Property {[version]$_.version} | Select-Object -Last 1

if(-not $nuget -or [version]$nuget.version -lt [version]$version){
    Write-Verbose "Installing NuGet $($nuget.Version)"
    $null = Install-PackageProvider -Name NuGet -MinimumVersion $nuget.version -Force
}

This will make sure nuget is ready and then you can run your command.

Install-Module -Name PSWindowsUpdate -Force -Confirm:$false

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.