I have a script like so:
test.ps1
param (
$name,
$age
)
function load-parameters()
{
$name = "Bob"
$age = "23"
Write-Host "name: " $name
Write-Host "age: " $age
}
load-parameters
Write-Host "name: " $name
Write-Host "age: " $age
Except instead of name and age, i have about 10 parameters that i'm loading and initializing inside load-parameters.
The problem I am trying to solve is trying to preserve the values of the initialization of (what i think are) global scope functions inside the script.
The function above returns:
name: Bob
age: 23
name:
age:
Are the local edits hardwired when you change them into functions? it looks like the implementation is that parameters are being passed by copy to functions you write inside a script.
I realize I can get around this by passing the variables by reference (if there is even a thing in powershell functions), but that would be ugly given the number of parameters i need to pass. is there a way to specify the scope of the variable when i'm doing the assignment inside function "load-parameters"?