Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permanent PowerShell variable

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

I'll need this variable to keep its value, because I'll be needing to reboot my server every now and then, and I don't want to lose these values.

like image 505
GwFiles Avatar asked Jan 13 '12 17:01

GwFiles


1 Answers

To store:

$variable|export-clixml -path $Location

To retrieve:

$variable = import-clixml -path $Location

Put that in a function if you want it, something like:

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

$location obviously contains the place in the filesystem where do you want to store the variable.

like image 70
mjsr Avatar answered Nov 10 '22 04:11

mjsr