1

Executing

Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted

in a Powershell 5 session,

Question

  • will its effect remain in subsequent new sessions?
  • If later I install a Powershell Core 7.x.x will those session affected?

(In general it is not clear for me how side by side installed PowerShell 5 and PowerShell Core 7.x.x how cross side effected in 5->7 and 7->5 direction)

4

1 回答 1

2

Set-PSRepository如和的文档中所述Register-PSRepository,任何更改都是持久的并且在用户范围内。它们适用于所有版本的 PowerShell,其中包括不同的版本。这意味着 PowerShell Core 6.x/PowerShell 7.x 也将看到同一用户的这些更改,即使在进行更改时未安装也是如此。这也扩展到您更改/注册的任何其他 PS 存储库。

我已经创建了一个测试实例并独立验证了这一点:

  • Windows PowerShell 5.1
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/
  • 已安装 PowerShell 7.1.2 x64
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/
于 2021-02-26T15:22:10.767 回答