PowerShell constant

Is there a way to define a variable in PowerShell, so when I open a new PowerShell window it will keep the same value?

I need this variable to save its value, because I will have to periodically restart my server, and I do not want to lose these values.

+5
source share
4 answers

Have you considered other alternative sources for storing a variable? Variables in PowerShell are usually saved only until the PowerShell session itself. However, there are several other sources that PowerShell can easily request for longer. In particular, the registry and file system.

, , , PowerShell (, ).

+1

:

$variable|export-clixml -path $Location

:

$variable = import-clixml -path $Location

, , - :

function LoadTHEvariable($location)
{
    $global:variable = import-clixml -path $Location
}

$location, , , .

+5

You can save your data in your PowerShell Profile .

+3
source

Consider using an environment variable.

+2
source

All Articles