I was recently trying to use PowerShelGet Install-Package to install a module from an Azure DevOps Artifacts hosted PowerShell Gallery using the following script

# For authentication use a PAT as the password, UID can be anything
$PATcreds = Get-Credential 
Register-PSRepository -Name BM -SourceLocation '<org>/_packaging/PowerShell/nuget/v2' -PublishLocation '<org>/_packaging/PowerShell/nuget/v2' -InstallationPolicy Trusted
Install-Package BlackMarble.Package -Source BM -Credential $PATcreds

The script did not work I was getting the error

Install-Package : Cannot find the path ‘C:\Users<user>\AppData\Local\Temp\936930114\BlackMarble.Package\BlackMarble.Package.0.3.79\BlackMarble.Package.psd1’ because it does not exist.

You could see a download progress bar that suggested the download had occurred, but no module was installed.


Turns out the answer was to not register the repository, but to use a URL in the -Source parameter to Install-Package.

Install-Package BlackMarble.Package  -Source<org>/_packaging/PowerShell/nuget/v2 -Credential $PATcreds

It sort of makes sense that there could be a bug such that URLs work and aliases, added via a register-psrepository, do not. Maybe a bug?

However, more strangely I have found that if the alias is registered the the Install-Package fails even if a URL is used. The complete solution is therefore to first unregister-psrepository the alias that match the URL you wish to use before running the Install-Package command.

All very strange