I have the following code:
$firstRun = 'True'
$file | ForEach-Object {
Function Do-Stuff {
if ($firstRun = 'True') {
write-host "null"
$firstRun = 'False'
}
}
Do-Stuff
}
When I call Function 'Do-Stuff', it will run the first time, no matter where I place $firstRun = 'False', it returns true and intiates the if block again. What am I doing wrong?
variable scope. i suspect that is where your glitch is occurring ...truewith tests for the boolean$True. it makes no difference in your code, but fits better with how PoSh handles False/True.