I have a feed for PowerShell modules in my VSTS project and I am using it as a private gallery, based on this article: https://roadtoalm.com/2017/05/02/using-vsts-package-management-as-a-private-powershell-gallery/
Everything works great when we run this on the machine. I need these modules as part of the release process, so the first task is to register this repo if it doesn't exist and then download and install the latest version of each module. The relevant part of my script is:
Install-PackageProvider -Name NuGet -Confirm:$false -RequiredVersion 2.8.5.208
Get-PSRepository | Where-Object {$_.Name -eq "MyPrivateFeed" -or $_.SourceLocation -eq "https://myproject.pkgs.visualstudio.com/_packaging/MyPrivateFeed/nuget/v2"} | Unregister-PSRepository
Register-PSRepository -Name "MyPrivateFeed" -SourceLocation "https://myproject.pkgs.visualstudio.com/_packaging/MyPrivateFeed/nuget/v2" -InstallationPolicy Trusted
$PAT = $(System.AccessToken) | ConvertTo-SecureString -AsPlainText -Force
$VSTSCredentials = New-Object -TypeName PScredential("dummy", $PAT)
Find-Module -Name * -Repository MyPrivateFeed -Credential $VSTSCredentials | Install-Module -Credential $VSTSCredentials
The PowerShell task in the release fails with:
WARNING: Unable to find module repositories.
PackageManagement\Register-PackageSource : The property 'Values' cannot be
found on this object. Verify that the property exists.
At C:\Program
Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4173
char:17
+ ... $null = PackageManagement\Register-PackageSource @PSBoundParamete ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Microsoft.Power...erPackageSource
:RegisterPackageSource) [Register-PackageSource], Exception
+ FullyQualifiedErrorId : PropertyNotFoundStrict,Microsoft.PowerShell.Pack
ageManagement.Cmdlets.RegisterPackageSource
The same exact script works on the same machine when I run it on ISE/Console (with replacing the token with the actual PAT of course) Anyone has any idea what is going on here?
I tried adding -PackageManagementProvider NuGet to Register-PSRepository but that didn't help