Tuesday, February 9, 2010

Powershell ISE does not honour scope operators

Write this in a script file and open that in Powershell ISE.

$Script:Abc=10

function abc

{

$k = 10

}

# Do some processing

$Script:Abc = 20

abc

Execute above statements using Run button in ISE and check get-variable. you will find that Abc is still set in. Next invocation of script will start with Abc being set as 20. Reason being that powershell ISE calls scripts using dot-sourcing.

Alternate for this trouble can be using all variables inside some functions.

No comments: