Skip to main content
added 54 characters in body
Source Link

PowerShell - Get OS Environmental Variables without Expanding

You can use the Get-Item cmdlet with the -path parameter and then pass that the path of the registry key containing the PSModulePath environmental variable.

You can then use the RegistryKey.GetValue Method along with DoNotExpandEnvironmentNames to get the string value of the PSModulePath environmental variable without expanding it.


PowerShell

$t$envarname = "PSModulePath"
$regkey    = Get-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
$t$envar     = $t$regkey.GetValue("PSModulePath"$envarname, "", "DoNotExpandEnvironmentNames")
ECHO $t$envar

Note: You will want to be sure you run this from administrator elevated PowerShell command prompt or ISE screen for it to work correctly.

enter image description here


Further Resources

The location of the user variables in the registry is: HKEY_CURRENT_USER\Environment. The location of the system variables in the registry is:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

When setting environment variables through the registry, they will not recognized immediately. One option is to log out and back in again. However, we can avoid logging out if we send a WM_SETTINGCHANGE message, which is just another line when doing this programatically, however if doing this on the command line it is not as straightforward.

Retrieves the value associated with the specified name and retrieval options. If the name is not found, returns the default value that you provide.

Use this overload to specify special processing of the retrieved value. For example, you can specify RegistryValueOptions.DoNotExpandEnvironmentNames when retrieving a registry value of type RegistryValueKind.ExpandString to retrieve the string without expanding embedded environment variables.

PowerShell - Get OS Environmental Variables without Expanding

You can use the Get-Item cmdlet with the -path parameter and then pass that the path of the registry key containing the PSModulePath environmental variable.

You can then use the RegistryKey.GetValue Method along with DoNotExpandEnvironmentNames to get the string value of the PSModulePath environmental variable without expanding it.


PowerShell

$t = Get-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
$t = $t.GetValue("PSModulePath", "", "DoNotExpandEnvironmentNames")
ECHO $t

Note: You will want to be sure you run this from administrator elevated PowerShell command prompt or ISE screen for it to work correctly.

enter image description here


Further Resources

The location of the user variables in the registry is: HKEY_CURRENT_USER\Environment. The location of the system variables in the registry is:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

When setting environment variables through the registry, they will not recognized immediately. One option is to log out and back in again. However, we can avoid logging out if we send a WM_SETTINGCHANGE message, which is just another line when doing this programatically, however if doing this on the command line it is not as straightforward.

Retrieves the value associated with the specified name and retrieval options. If the name is not found, returns the default value that you provide.

Use this overload to specify special processing of the retrieved value. For example, you can specify RegistryValueOptions.DoNotExpandEnvironmentNames when retrieving a registry value of type RegistryValueKind.ExpandString to retrieve the string without expanding embedded environment variables.

PowerShell - Get OS Environmental Variables without Expanding

You can use the Get-Item cmdlet with the -path parameter and then pass that the path of the registry key containing the PSModulePath environmental variable.

You can then use the RegistryKey.GetValue Method along with DoNotExpandEnvironmentNames to get the string value of the PSModulePath environmental variable without expanding it.


PowerShell

$envarname = "PSModulePath"
$regkey    = Get-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
$envar     = $regkey.GetValue($envarname, "", "DoNotExpandEnvironmentNames")
ECHO $envar

Note: You will want to be sure you run this from administrator elevated PowerShell command prompt or ISE screen for it to work correctly.

enter image description here


Further Resources

The location of the user variables in the registry is: HKEY_CURRENT_USER\Environment. The location of the system variables in the registry is:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

When setting environment variables through the registry, they will not recognized immediately. One option is to log out and back in again. However, we can avoid logging out if we send a WM_SETTINGCHANGE message, which is just another line when doing this programatically, however if doing this on the command line it is not as straightforward.

Retrieves the value associated with the specified name and retrieval options. If the name is not found, returns the default value that you provide.

Use this overload to specify special processing of the retrieved value. For example, you can specify RegistryValueOptions.DoNotExpandEnvironmentNames when retrieving a registry value of type RegistryValueKind.ExpandString to retrieve the string without expanding embedded environment variables.

added 909 characters in body
Source Link

PowerShell - Get OS Environmental Variables without Expanding

You can use the Get-Item cmdlet with the -path parameter and then pass that the path of the registry key containing the PSModulePath environmental variable.

You can then use the RegistryKey.GetValue Method along with DoNotExpandEnvironmentNames to get the string value of the PSModulePath environmental variable without expanding it.


PowerShell

$t = Get-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
$t = $t.GetValue("PSModulePath", "", "DoNotExpandEnvironmentNames")
ECHO $t

Note: You will want to be sure you run this from administrator elevated PowerShell command prompt or ISE screen for it to work correctly.

enter image description here


Further Resources

The location of the user variables in the registry is: HKEY_CURRENT_USER\Environment. The location of the system variables in the registry is:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

When setting environment variables through the registry, they will not recognized immediately. One option is to log out and back in again. However, we can avoid logging out if we send a WM_SETTINGCHANGE message, which is just another line when doing this programatically, however if doing this on the command line it is not as straightforward.

Retrieves the value associated with the specified name and retrieval options. If the name is not found, returns the default value that you provide.

Use this overload to specify special processing of the retrieved value. For example, you can specify RegistryValueOptions.DoNotExpandEnvironmentNames when retrieving a registry value of type RegistryValueKind.ExpandString to retrieve the string without expanding embedded environment variables.

PowerShell - Get OS Environmental Variables without Expanding

You can use the Get-Item cmdlet with the -path parameter and then pass that the path of the registry key containing the PSModulePath environmental variable.

You can then use the RegistryKey.GetValue Method along with DoNotExpandEnvironmentNames to get the string value of the PSModulePath environmental variable without expanding it.


PowerShell

$t = Get-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
$t = $t.GetValue("PSModulePath", "", "DoNotExpandEnvironmentNames")
ECHO $t

Note: You will want to be sure you run this from administrator elevated PowerShell command prompt or ISE screen for it to work correctly.

enter image description here


Further Resources

Retrieves the value associated with the specified name and retrieval options. If the name is not found, returns the default value that you provide.

Use this overload to specify special processing of the retrieved value. For example, you can specify RegistryValueOptions.DoNotExpandEnvironmentNames when retrieving a registry value of type RegistryValueKind.ExpandString to retrieve the string without expanding embedded environment variables.

PowerShell - Get OS Environmental Variables without Expanding

You can use the Get-Item cmdlet with the -path parameter and then pass that the path of the registry key containing the PSModulePath environmental variable.

You can then use the RegistryKey.GetValue Method along with DoNotExpandEnvironmentNames to get the string value of the PSModulePath environmental variable without expanding it.


PowerShell

$t = Get-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
$t = $t.GetValue("PSModulePath", "", "DoNotExpandEnvironmentNames")
ECHO $t

Note: You will want to be sure you run this from administrator elevated PowerShell command prompt or ISE screen for it to work correctly.

enter image description here


Further Resources

The location of the user variables in the registry is: HKEY_CURRENT_USER\Environment. The location of the system variables in the registry is:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

When setting environment variables through the registry, they will not recognized immediately. One option is to log out and back in again. However, we can avoid logging out if we send a WM_SETTINGCHANGE message, which is just another line when doing this programatically, however if doing this on the command line it is not as straightforward.

Retrieves the value associated with the specified name and retrieval options. If the name is not found, returns the default value that you provide.

Use this overload to specify special processing of the retrieved value. For example, you can specify RegistryValueOptions.DoNotExpandEnvironmentNames when retrieving a registry value of type RegistryValueKind.ExpandString to retrieve the string without expanding embedded environment variables.

Source Link

PowerShell - Get OS Environmental Variables without Expanding

You can use the Get-Item cmdlet with the -path parameter and then pass that the path of the registry key containing the PSModulePath environmental variable.

You can then use the RegistryKey.GetValue Method along with DoNotExpandEnvironmentNames to get the string value of the PSModulePath environmental variable without expanding it.


PowerShell

$t = Get-Item -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
$t = $t.GetValue("PSModulePath", "", "DoNotExpandEnvironmentNames")
ECHO $t

Note: You will want to be sure you run this from administrator elevated PowerShell command prompt or ISE screen for it to work correctly.

enter image description here


Further Resources

Retrieves the value associated with the specified name and retrieval options. If the name is not found, returns the default value that you provide.

Use this overload to specify special processing of the retrieved value. For example, you can specify RegistryValueOptions.DoNotExpandEnvironmentNames when retrieving a registry value of type RegistryValueKind.ExpandString to retrieve the string without expanding embedded environment variables.