New-Variable -Name GlobalVar -Value "Initial" -Scope "Global" write "GlobalVar is $GlobalVar" $script = { param( $server, $mycred ) $GlobalVar="Different" } # Passing of the parameters to the block through argumentlist. Invoke-Command -credential $mycred -ComputerName $server -ScriptBlock $script -ArgumentList $server,$mycred write "GlobalVar is $GlobalVar" Output is GlobalVar is Initial GlobalVar is Initial It should be as below as the $GlobalVar is modified in the script block... GlobalVar is Initial GlobalVar is Different
↧
How to pass the value out of the script, I am not sure how to use global or reference variable.
↧