I am re-posting something I posted in a small Slack group.
I started with showing how easy it can be to let your editor (in this case VSCode which personally I can’t see why you would be using anything else but …) come in and make your code look right. Let’s face it, we have an idea for what we are coding, and we want to stay focused on that. Between interruptions, writing, testing, writing again just focus on the task at hand is ideal. One thing that can help with that is the code formatting capabilities of your Editor/IDE.
So in the first video I have a simple scratchpad script where I am testing an If\ElseIf statement versus a Switch statement. There is nothing special in the code, matter of fact it just might be flawed, hence why it is a “scratchpad” script. The point is I was working through and then used Format Document to dress up the code (I believe there is also the use of “Trim Trailing Whitespaces” involved as well).
So as you see the format did dress up my sloppy code but I was not thrilled on how that destroyed my concise switch statement elements. Yes it formatted according to the settings in my settings.json file but…
I kept thinking about that scenario and then I remembered the setting that would probably work through this. In the following video I show the same code, format and the destruction, I mean expansion of my switch elements, Ctrl-Z, change the setting and the Format Document works to my liking…
So I stay in OTSB but because they are simple elements my Switch statement stays just a few lines.
This applies to other languages in Visual Studio Code but this is a PowerShell blog so… If you are using Visual Studio Code for PowerShell work, go into your Settings file (Use the ⚙ icon and select settings and then search for “PowerShell Code Format” . When you get to the Code Formatting: Preset check here for a great reference when you select the formatting style.
Again, I welcome any questions or feedback you might have. Now back to work.
By default, VSCode will update your installed extensions automatically. Personally, I prefer to be notified of extensions to be updated and view the Changelog. This is a quick recording of the process, to include the setting you can change depending on your preference, how to update your VSCode extensions.
I have to preface this with I truly respect the idea and the gentleman who initiated ScriptCop. That said it sort of brings up a sore point that struck me during the last Scripting games.
I am all for beautiful functioning code but Powershell seems to have brought a large amount of developer oriented folks into the community and the mix with System Administrators becomes interesting. When I first started with Powershell I was doing lots of vbscript so I was able to focus on code and listening to the great minds who were not just teaching the powerful language but to optimize it.
I would love to sit and perfect my code, but as my new job dictates, there isn’t time to write beautiful code. And that is just one issue I have with the critiquing. Granted I think that an employer who wants you to apply Powershell technology but doesn’t think you should spend time doing it right is problematic but, that is how it is. Additionally when I write code, I have to think about it’s readability, and readability amongst a varied expertise. Things like long concise pipelines. They look very cool and are normally very proficient, but think about the SysAdmin who might have to perform an after hours support call when it isn’t functioning correctly. Despite the huge powershell community, my day to day experience indicates there are more Windows System Administrators that are not even looking at Powershell and most never progressed beyond batch files. Breaking a pipeline into separate steps is just a more debuggable format in my opinion.
I do think ScriptCop is a great idea but maybe applied more towards a uniform way to apply approved standards to a library of scripts.
So, this post is more about personal loyalties than Powershell itself. The recent changes with PowerGUI have me contemplating changing my default editor. I have found PowerGUI to be great, but part of the greatness was the Product Manager. The product is great, especially the editor. I did buy the pro version and quite frankly in my environment it didn’t give me anything I could use but it seemed right to support the product as I as endorsing it to everyone I worked with.
At this point I am considering going back to PowershellPlus but after I played with the most recent beta I miss the original version. I still use Sapien for when I have to work with vbscript code but I find it way too bloated when comparing it PowerGUI. When it’s all said and done I think I will be deciding between the ISE and the free PowerGUI.