Pushing PowerShell Set-PSRepository
I am need to push the SQLServer module for PowerShell to all our client workstations. In order to do this, I have to update NuGet, set the PSRepository to Trusted and then install the module. I would like to do this without any user interaction. However, I keep getting the following error on Set-PSRepository:
Exception calling "ShouldContinue" with "2" argument(s): "Windows PowerShell is in NonInteractive mode. Read and
Prompt functionality is not available."
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7455 char:8
+ if($Force -or $psCmdlet.ShouldContinue($shouldContinueQueryMessag ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : PSInvalidOperationException
Here is what I have:
- Step One
-
Install-PackageProvider -Name "NuGet" -MinimumVersion "2.8.5.201" -ForceBootStrap
- Step Two
-
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
- Step Three
-
Install-Module -Name SqlServer -Confirm:$false -AllowClobber
Step two is the failed step.
Comments
It looks like it's trying to display an "Are you sure?" type of prompt. Trying adding -Force.
There is no -Force cmd for Set-PSRepository
Oops, I should have checked the documentation first.
Are you sure you need Set-PSRepository? When I wrote this module installation script I never ran into a situation where I needed to use it.
https://github.com/pdq/PowerShell-Scanners/blob/master/PowerShell%20Scanners/_Shared/Install%20and%20Import%20Module.ps1
I disabled step 2 and still received the same error. I am assuming this is the correct syntax for the module install:
I use -Force instead of -Confirm:$false on Install-Module.
Changed to -Force and still same error.
Had to add -Scope CurrentUser to step 1 and 3. Here is what I have now and it works like a charm with no prompts for the client workstation.