I want to have a function in which the result is stored in a variable where the function defines the variable name - essentially this:
function testfunction ($varname,$text){
$readhost = read-host -prompt "$text"
new-variable -name $varname -value $readhost
}
though when entering:
testfunction outputvar sampletext
get-variable -name outputvar
I just get an error that the variable "outputvar" doesnt exist. what am I missing here? Tried a number of other stuff but nothing seemed to work - what i want in the end is a variable that is named "outputvar" that contains the prompt input, just to clarify.
$global:to create a global variable, but it would be better to just return a value to a variable. I'll write an answer with an example.