Hi Greg There are some very good PS courses on MVA, right from the horse's (Snover's) mouth.
I have moments with PS where I'm stunned how much I get done and how fast. Other days, I want to poke my eyes out with a sharp stick after trying to do something that seemed trivial. Regards, Greg Dr Greg Low 1300SQLSQL (1300 775 775) office | +61 419201410 mobile│ +61 3 8676 4913 fax SQL Down Under | Web: www.sqldownunder.com<http://www.sqldownunder.com> ________________________________ From: ozdotnet-boun...@ozdotnet.com <ozdotnet-boun...@ozdotnet.com> on behalf of Greg Keogh <gfke...@gmail.com> Sent: Saturday, July 8, 2017 3:28:01 PM To: ozDotNet Subject: Re: Powershell testing 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 <gfke...@gmail.com<mailto:gfke...@gmail.com>> 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