Adding module repository that requires authentication

Product: PowerShell Universal
Version: 3.3.3

I’m trying to add our PowerShell repository that is hosted on Azure DevOps. I initially followed the instructions for adding a private repository before finding out that I needed to be using cmdlets from PSGet v3.

However, when running the following script I am getting an error with the credentials:

$parameters = @{
    Name = "myorgPowerShell"
    Uri = "https://pkgs.dev.azure.com/myorg/Infrastructure/_packaging/myorgPowerShell/nuget/v3"
    Trusted = $true
    Priority = 50
    CredentialInfo = New-Object Microsoft.PowerShell.PowerShellGet.UtilClasses.PSCredentialInfo ('PSUSecretStore', 'DevOpsPAT')
}

Register-PSResourceRepository @parameters
Cannot find type [Microsoft.PowerShell.PowerShellGet.UtilClasses.PSCredentialInfo]: verify that the assembly containing this type is loaded. 
Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. 

I think I’ve found my issue here. Although it’ll need support from the PSU devs.

PSU as it stands has v3.0.12 of PowerShellGet installed by default. Looking at the repository for the module it looks like the -CredentialInfo parameter wasn’t added until v3.0.13.

I’ve tried to override what gets loaded by default with a newer version, but Import-Module gives me an error of Assembly with same name is already loaded, yet I can’t seem to unload the one that’s there.

Having tested this out a bit further today I can now register the repository if I use a PowerShell 7 environment and explicitly import a newer version of PowerShellGet at the top of my script. The Assembly with the same name... error only occurs with the Integrated environment and I can’t remove the existing version.

However, despite that I’m not seeing the list of packages in the feed, but I suspect that’s a whole other issue entirely!