DEV Community


Posted on

PowerShell Readability For Others


I've been meaning to start some sort of online blog to jot down snippets, ideas, and solutions to begin giving back to the online community I regularly benefit from. Here is my first short post to begin that journey!

The Great Debate

I work on a team of 6 developers that write automated solutions. We are currently a little divided in our preferred languages with a heavier focus on Python. Unfortunately, I'm the PowerShell guy that has been slowly learning Python to support different projects and our overall code base.

I've been having a debate with myself over the past couple weeks. Do I go out of my way to make my PowerShell more readable or stick to the syntax I've learned and are more comfortable writing?

Can You Read This Now?

Here is a quick example with a method used very frequently: piping to Where-Object to perform operations based on an object property value.

This is the way I'm used to writing my code:

Get-NetworkAdapter | Where-Object {$_.NetConnectionID -eq "NIC1"}
Enter fullscreen mode Exit fullscreen mode

For anyone familiar with PowerShell, this probably makes perfect sense. However, on my team this presents an initial roadblock concerning readability.

Based on a poll I sent out, they seemed more familiar/comfortable when the same command was presented this way:

Get-NetworkAdapter | Where NetConnectionID -eq "NIC1"
Enter fullscreen mode Exit fullscreen mode

Final Thoughts

Overall, I think our decision is going to come down to what works best for our team. I'm fine to give a little, as some of the syntax of PowerShell is quite different than Python. However, I will also be challenging them to invest some time learning PowerShell as I learn Python :)

Let me know what you think in the comments. I may later turn this into a series about our team adventure to being a multi-language group.

Thanks for reading!

Top comments (0)