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\\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 "" -ForceBootStrap
  • Step Two
  • Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
  • Step Three
  • Install-Module -Name SqlServer -Confirm:$false -AllowClobber

Step two is the failed step.



Date Votes
  • 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.


  • I disabled step 2 and still received the same error.  I am assuming this is the correct syntax for the module install:

    Install-Module -Name SqlServer -Confirm:$false -AllowClobber

  • 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.

    • Step 1
    • Install-PackageProvider -Name "NuGet" -MinimumVersion "" -Scope CurrentUser -Force
    • Step 2
    • Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
    • Step 3
    • Install-Module -Name SqlServer -Confirm:$false -AllowClobber -Scope CurrentUser

Please sign in to leave a comment.

Didn't find what you were looking for?

New post