I think I found the cause of the weird behaviour. You have to put function
definitions at the top, before the outer level code. It's not like C/C++/C#
or a real language, it's read from the top down (event BAT files are better
than that). I don't know how it intermittently worked, but I supposed it's
cached the functions, it's the only crazy explanation.

Calling COM functions from PS is really fragile work. The slightest whim of
a mistake will result in a cascade of incomprehensible errors.

Last night I wondered why the script was failing for over half an hour
without any useful message. It turns out I had the MSI file open in Orca
and couldn't see the window, which was causing the script to crash with a
generic COM error.

*GK*

On 8 July 2017 at 15:10, Greg Keogh <[email protected]> wrote:

> How to people write PowerShell scripts in a productive way?
>
> I'm writing my first non-trivial one to query and update the tables in MSI
> files. I reckon I have wasted more than half the coding time (many hours)on
> utterly infuriating and bewildering problems. I'm writing the script in ISE
> and I hit F5 to run it and check the results.
>
> After making a code change I hit F5 and it runs the code before the
> change, the second F5 runs with the change. Even saving the script makes do
> different and I have to hit F5 twice to see the results.
>
> If I make a small error the script crashes. Sometimes when I fix the error
> it continues to crash with an unrelated error as if I never corrected it.
> It's like an error gets "stuck" and can't be undone. I made a tiny
> correctional change about 15 minutes ago and the script crashes non-stop
> with a "not recognised" error, which I know is bullshit. I've even tried
> rebooting, but the correct script is still crashing.
>
> Is this a joke. What century am I in?
>
> *Greg K*
>

Reply via email to