Posted in Powershell

Finding tidbits; this community is great

Powershell + DevOps Summit 2019 has been going strong this week. Sadly I am unable to attend events like this so I do what I can to follow the action. One of the ways I follow it is via constantly updating a Twitter search for #PSHSummit. This has been a great feed of information.

One of the posts, not sure if it is specific to the Summit but was a quick tip like statement that made me say “dang”. I will go further with where I went with the content in an upcoming post but I just wanted to ink (digitally of course) my thoughts on it.

I am a Systems guy, we learn how to do things, we jot it down and then we “automate” it. No matter the shell, we create these scripts. In my case, they started as just lines of commands.

Time, many years for me, passes and we start sharing these and we begin to not only take pride in the actions of our scripts but we start adding comments, looking at the layout etc so that when we do share our work we have a little more pride.

With PowerShell and probably more so the editors we start utilizing we go even further with the format of the script as much as the complexity of the work it is performing. It is still evolving.

So this nugget touched on declaring variables, specifically for a file object. Ouch, I can just look at the code I was working on at the time and say…. [System.String] was what I was using to declare a variable for just that… Yes it works, but why didn’t I just go the extra step (and again with the editors/IDE’s available today it is right there) and declare it as FileInfo or DirectoryInfo. Lesson learned.

I mentioned an upcoming post because as soon as I read that I had to start testing… for the simple use of [System.IO.FileInfo], in just the script I was working on I could reduce lines of code I used right then and there…

End of the day… code looks cooler and I have a sneaky suspicion the execution of the code will be more efficient.

Thanks Mr Ruddy.
var_declare