跳过 powershell 启动检查新版本

skip powershell startup check for new version

tl;dr 如何强制 Powershell 跳过检查新版本?

当我启动 Powershell 7 时,它会检查是否有新版本的 Powershell。

目前,这看起来像

PowerShell 7.0.0
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/powershell
Type 'help' to get help.

   A new PowerShell stable release is available: v7.1.3
   Upgrade now, or check out the release page at:
     https://aka.ms/PowerShell-Release?tag=v7.1.3

新版本的检查延迟了 Powershell 的启动。有时这个延迟是十到二十秒。这有点烦人。 我想跳过 powershell 版本检查。

$env:POWERSHELL_UPDATECHECK = 'Off'

By default, PowerShell subscribes to one of two different notification channels depending on its version/branch. Supported, Generally Available (GA) versions of PowerShell only return notifications for updated GA releases. Preview and Release Candidate (RC) releases notify of updates to preview, RC, and GA releases.

The update notification behavior can be changed using the POWERSHELL_UPDATECHECK environment variable. The following values are supported:

Off turns off the update notification feature
Default is the same as not defining POWERSHELL_UPDATECHECK:
GA releases notify of updates to GA releases
Preview/RC releases notify of updates to GA and preview releases
LTS only notifies of updates to long-term-servicing (LTS) GA releases

可以将对 $env:POWERSHELL_UPDATECHECK 的更改添加到位于 $profile 的配置文件脚本中。

notepad $profile

来源: https://toastit.dev/2020/03/13/ps7now-update-notifications/

接受的答案对我有用,但有一些调整。

在 PS 配置文件 $profile 中设置 $env:POWERSHELL_UPDATECHECK = 'Off' 没有禁用更新检查。

我不得不通过系统对话框设置环境变量:

以这种方式设置变量后PS不再挂起寻找新版本:

PowerShell 7.1.0
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS7 >