This allows even native commands to be handled gracefully by try/catch. Just because this isnât a terminating error doesnât mean you wonât eventually run into one. Chose to handle your errors up front and you are surprised less often in the future when a script just stops working. Also the issue youâre describing here today is due to the vast improvements made to ps coreâs error handling, much of which was driven by Kirk Munro who sadly has abandoned the powershell project because many of his and other community pull requests were rejected or ignored by the powershell team. From an outsiders perspective it seems to be internal politics and bureaucracy.
Iâve learned over the years. The most innocent commands can throw the most unexpected terminating errors which abruptly stops scripts. So even logging just stops with no insight other than last thing logged.
I personally donât like error preference to be âstopâ, because often times Write-Error is useful to signal something bad that is not neccessrily so bad that it would have stop the script.
A workaround with Write-Error -EA "Continue" for such non terminating cases due to error preference becomes tedious, and with time itâs hard to keep track of where did you put -EA and where not, in the future when you decide to refactor code you would have to change every Write-Error -EA thing and could easily lost the track.
I think the best method is that for each script that you write you also write a companion unit test script with rigorous test cases to handle all possible bad scenarios that come to your mind.
OK, that explains why Windows PS should be avoided, however not everything works well in PS Core.
I often times think what if I abandon Windows PS entirely and never use it again, but thatâs just impossible, if nothing else itâs useful for testing things which donât work in Core.
I have a script that supports both local and remote systems and also needs to support both WPS and PS Core. Likely a better way, but I chose to set a global flag based on the runtime version and adjust the script accordingly. I also updated all deprecated calls that were not supported in Core.
One thing I noticed, and the main reason for this comment, was a huge performance gain with PS Core on the order of 40 to 50% in the time the script takes to run. I was pleasantly surprised and I did NOT take advantage of -Parallel.
The part that took the most time to figure between the two versions was differences with Windows Forms. I had to play around with Positioning and Size properties of the controls to where the form looked the same for both versions. Aside from that, the code did not take much time to adjust.