user989865
user989865

Reputation: 637

PowerShell Install-Module Command fails in Azure DevOps Pipeline

I have the following PowerShell cmdlet to install PowerShell module when the pipeline is being executed

steps:
    - powershell: |
    
        Install-PackageProvider Nuget -Scope CurrentUser -Force
        Install-module PSScriptAnalyzer -force -Scope CurrentUser
        Install-module PSPesterTest -force -Scope CurrentUser
      displayName: 'Install required PowerShell modules'

This however throws an error of "No repository with the name 'PSGallery' was found". Please, can anyone, point me to a workaround with regards this issue?

Upvotes: 2

Views: 5341

Answers (2)

Hugh Lin
Hugh Lin

Reputation: 19391

There are some problems with your script syntax, please try the following script:

pool:
  vmImage: 'windows-2019'

steps:

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
      Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
      Install-Module -Name PSPesterTest -Force -Scope CurrentUser

enter image description here

Here is the official document you can refer to.

Upvotes: 4

Casper Dijkstra
Casper Dijkstra

Reputation: 1885

Edit:

Install-module should be Install-Module. Moreover,by restoring the PSRespository back to default your problem is hopefully resolved :)

Register-PSRepository -Default

Upvotes: 0

Related Questions