Set-PSRepository
如和的文档中所述Register-PSRepository
,任何更改都是持久的并且在用户范围内。它们适用于所有版本的 PowerShell,其中包括不同的版本。这意味着 PowerShell Core 6.x/PowerShell 7.x 也将看到同一用户的这些更改,即使在进行更改时未安装也是如此。这也扩展到您更改/注册的任何其他 PS 存储库。
我已经创建了一个测试实例并独立验证了这一点:
PS C:\Users\TestUser01> Get-CimInstance -Query 'SELECT Caption,Version FROM Win32_OperatingSystem' | select Caption,Version
Caption Version
------- -------
Microsoft Windows 10 Enterprise LTSC 10.0.17763
PS C:\Users\TestUser01> $PSVersionTable.PSVersion.ToString()
5.1.17763.1490
PS C:\Users\TestUser01> $null -eq (gcm pwsh -ea:ig)
True
PS C:\Users\TestUser01> Get-PSRepository
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Untrusted https://www.powershellgallery.com/api/v2
PS C:\Users\TestUser01> Set-PSRepository PSGallery -in Trusted
PS C:\Users\TestUser01> Register-PSRepository ExampleRepo -so 'http://example.com'
PS C:\Users\TestUser01> Get-PSRepository
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Trusted https://www.powershellgallery.com/api/v2
ExampleRepo Untrusted http://example.com/
PS C:\Users\TestUser01> $PSVersionTable.PSVersion.ToString()
7.1.2
PS C:\Users\TestUser01> Get-PSRepository
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Trusted https://www.powershellgallery.com/api/v2
ExampleRepo Untrusted http://example.com/