I have been merrily going along my way developing a fairly massive XML file to be used by the PowerShell script I am crafting. After making several changes I have more comments on PowerShell to make.
- Do not call iex or Invoke-Expression from within a PowerShell script, these commands do odd things with the memory image of a script. Perhaps it is the nature of my script, where I am passing long Linux shell commands through the iex command. For some reason, iex decided to interpret the Linux shell command as PowerShell but only for 5 of 400 or so commands. This inconsistent behavior took several weeks to uncover. As an aside iex caused me similar problems when using it within a simple comparison statement, $cv=iex “$vc -$cmp $pval”, where $vc and $pval were both integers and $cmp was actually set to eq. So it was trying to do an equality comparison.
- Never use > as a means for doing a greater-than comparison. Instead the proper operator is -gt. This caused another week of debugging to discover. Once you use > then debuggers tend to have serious issues, like PowerGUI and they loose track of the program.
These two gotchas took nearly forever to find, the first apparently leads to some sort of memory overlay and the second causes debuggers and other things to behave oddly.
When you are running a program and suddenly the output is showing the actual PowerShell script instead of what was expected, you know there are serious memory issues going on. When programming Linux scripts we would call that a stack corruption.