PowerShell is a forgiving scripting language, and that’s part of its appeal. When you’re working with PowerShell, you can borrow code from C#, .NET, or even COM objects and integrate them seamlessly into your code. This sounds great in theory, but when it comes to working on your code in a team of PowerShell developers, it’s best to stick to PowerShell. By straying from it, you could end up leaving your team confused, making your code less understandable, and really giving the next person who needs to edit your scripts a hard time.
Use Native PowerShell Where Possible
With PowerShell, you have a nearly limitless toolset. If you need to accomplish something outside of what you can find PowerShell commands for, you have the option to use COM objects, .NET classes, and so on. That being said, don’t immediately jump to using these “non-PowerShell” methods. When there’s an existing PowerShell way of doing something, use it! There’s a strong chance that it’ll process better, faster, or give you an output that’s easier to use in the end.
You test the script, it reads the file as expected and you move on. However, a few days go by and maybe someone else on your team opens up the script or you decide to share it with the PowerShell community. Soon someone finds a bug and begins to attempt to troubleshoot the problem and see this line. Not having any programming knowledge at all, they immediately are stuck and much dive into Google figuring out what this means.
Only revert to calling .NET methods rather than PowerShell commands if you require the highest performance possible or there is no PowerShell command available to do what you need to.
Tip Source: https://twitter.com/JimMoyle
Further Learning
Use Approved, Standard Function Names
PowerShell allows you to assign any name to a function you’d like. You can call a function foo, do-thing, or Get-Thing. PowerShell doesn’t care as long as you call that function by the assigned name. Even though you can assign whatever name you’d like doesn’t mean you should.
PowerShell has preferred naming standard you should follow for all of your functions. This standard specifies that all commands should start with a verb, a dash, and followed by a singular noun such as Get-Thing, Start-Service, Invoke-Command, and so on. You are free to use whatever noun you’d like that makes sense, but you should only use “approved verbs.”
PowerShell strongly encourages you to use an “approved verb” or any verb you see when you run the Get-Verb cmdlet. Use any of these verbs that make sense for your situation.
Once you find a verb that fits, assign a singular noun. Don’t assign a plural noun like Get-Things. Although your function may, in fact, get things (plural), does it always? When you use the pipeline, your function isn’t technically getting multiple things; it’s processing them one at a time. Always use a singular noun to provide an accurate name of what your function does.