Reputation: 107
This is my powershell function:
function A
{
$a = "securestring"
return $a
}
$b = A
Remove-Variable -Name b -Scope "Local"
$b is no longer in memory by now. But what about $a?
Upvotes: 0
Views: 544
Reputation: 19684
The easy answer: no. After it exits that scope, its variables are gone. Also, if you want $B to capture the output of the function, you should really do something like this instead:
Function A
{
"securestring"
}
$B = A
> $B
> securestring
> $B.GetType().Name
> String
Remove-Variable -Name B -Scope 'Local'
> $B
> $B.GetType()
> You cannot call a method on a null-valued expression.
Your example is a bit convoluted.
Upvotes: 1