About PowerShell update notifications

It’s nice that we have such a good documentation about_update_notifications 🙂

What is unclear for me that could be improved is what kind of environment variable are required and when the check happens.

First let’s see how these notifications look like:

I naively set an environment variable inside the current user profile.

if ($PSVersionTable.PSEdition -eq 'Core') {
 Set-Item -Path Env:\POWERSHELL_UPDATECHECK -Value 'Off'
}

It means that on Windows, a ‘Process‘ environment variable being set using PowerShell profiles doesn’t work.
The notification check happens before a profile is processed.

Let’s test a ‘User‘ environment variable

# Set
[Environment]::SetEnvironmentVariable(
 'POWERSHELL_UPDATECHECK',
 'Off',
 [System.EnvironmentVariableTarget]::User
)
# Get
[Environment]::GetEnvironmentVariables(
 [System.EnvironmentVariableTarget]::User
)

A new shell or process should be started to take into account this new User environment variable defined.
The notification check doesn’t occur in this case.

Delete first the User env. variable.

# Set to NUL to delete
[Environment]::SetEnvironmentVariable(
 'POWERSHELL_UPDATECHECK',
 $null,
 [System.EnvironmentVariableTarget]::User
)
# Get
[Environment]::GetEnvironmentVariables(
 [System.EnvironmentVariableTarget]::User
)

Set a ‘Machine‘ environment variable

# Set
[Environment]::SetEnvironmentVariable(
 'POWERSHELL_UPDATECHECK',
 'Off',
 [System.EnvironmentVariableTarget]::Machine
)
# Get
[Environment]::GetEnvironmentVariables(
 [System.EnvironmentVariableTarget]::Machine
)

A new shell or process should be started to take into account this new Machine environment variable defined.

The variable appears to be defined in the PowerShell environment drive and can be retrieved using a .Net method call.

What else works?
If you are in a Command Prompt, this works:

If you are in a Windows PowerShell console,

Set-Item -Path Env:\POWERSHELL_UPDATECHECK -Value 'Off'

The environment variable can be inherited by the parent process whatever its type.

Conclusion: The type is actually irrelevant.
You have multiple choices to set this environment variable. Either in the Windows PowerShell profile (if pwsh.exe is started from there), or in the Machine or User environment variables (if pwsh.exe is started by double-clicking or has cmd.exe as a parent process). What doesn’t work is a Process environment variable defined in a PowerShell (Core) profile.

1 thought on “About PowerShell update notifications

  1. Pingback: Dew Dump – June 18, 2020 (#3217) | Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.