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.

0

Comments

7 comments
Date Votes
  • It looks like it's trying to display an "Are you sure?" type of prompt. Trying adding -Force.

    0
  • There is no -Force cmd for Set-PSRepository

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

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

    0
  • I use -Force instead of -Confirm:$false on Install-Module.

    0
  • Changed to -Force and still same error.

    0
  • 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 "2.8.5.201" -Scope CurrentUser -Force
    • Step 2
    • Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
    • Step 3
    • Install-Module -Name SqlServer -Confirm:$false -AllowClobber -Scope CurrentUser
    0

Please sign in to leave a comment.

Didn't find what you were looking for?

New post