Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell - persist variable outside of function

Tags:

powershell

I'm trying to import an xml file and store as a variable for the remainder of a powershell session. The import is obviously successful but the variable content does not persist outside of the function.

Function auth
{
$cred = import-clixml -Path c:\temp\cred.xml
}
like image 392
josnoir Avatar asked Aug 30 '26 18:08

josnoir


1 Answers

try this:

Function auth
{
    $global:cred = "test"
}

auth
$global:cred
like image 178
Esperento57 Avatar answered Sep 03 '26 06:09

Esperento57