Replacing the Default PSRepository with your own (For PowerShell v 5.0.10586.117)

 

The script below is a template for changing the default PSRepository location.


#Script to change the default PSGallery URLs to custom ones (Needed for PowerShell 5.0.10586.117)
$xmlPath = "${env:APPDATA}\Microsoft\Windows\PowerShell\PowerShellGet\PSRepositories.xml" -ireplace "Roaming","Local"

$config = Import-Clixml -Path $xmlPath

$config.Item("PSGallery").SourceLocation = '<YOUR_INTERNAL_PROGET_URL_HERE>'
$config.Item("PSGallery").PublishLocation = '<YOUR_INTERNAL_PROGET_URL_HERE>'
$config.Item("PSGallery").ScriptSourceLocation = 'https://www.powershellgallery.com/api/v2/items/psscript/'
$config.Item("PSGallery").ScriptPublishLocation = 'https://www.powershellgallery.com/api/v2/package/'
$config.Item("PSGallery").Trusted = $true
$config.Item("PSGallery").Registered = $true
$config.Item("PSGallery").InstallationPolicy = 'Trusted'
$config.Item("PSGallery").PackageManagementProvider = 'NuGet'
$config.Item("PSGallery").ProviderOptions = $config.Item("PSGallery").ProviderOptions

Export-Clixml -Path $xmlPath -InputObject $config

Thanks to Richard for his deep research on this issue …

Using Agent Ransack, I found that the repository data is stored in “c:\Users\\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet\PSRepositories.xml”

Richard Siddaway's Blog

In this post – https://richardspowershellblog.wordpress.com/2016/09/17/powershell-repositories/ – I stated that you could unregister the default PowerShell repository. I also said that the statement in the documentation for Unregister-PSrepository that you couldn’t unregister PSGallery was incorrect.

A couple of readers have left comments stating that they tried it and got an error message stating that PSGallery can’t be unregistered.

I did my first test on Windows 10 latest preview build – build 14926

PS> $PSVersionTable

Name Value
—- —–
PSVersion 5.1.14926.1000
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
BuildVersion 10.0.14926.1000
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

I’ve just test on Windows Server 2016 TP5

PS C:Windowssystem32> $PSVersionTable

Name Value
—- —–
PSVersion 5.1.14300.1000
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
CLRVersion 4.0.30319.42000
BuildVersion 10.0.14300.1000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

The version of PowerShell 5.1 on Server 2016 TP5 doesn’t have the –Default parameter on Register-PSrepositiry but this works

Register-PSRepository…

View original post 25 more words

Advertisements