Walkthrough: An example of how I write PowerShell functions
A couple of days ago I posted a blog article titled “PowerShell function: Test-ConsoleColor provides a visual demonstration of the foreach scripting construct” and today I thought I would walk you through that function step by step since it’s what I consider to be a well written PowerShell function.
It starts out by using the #Requires statement to require at least PowerShell version 3 or it won’t run. It also requires that the PowerShell Community Extensions module be installed since it uses a function from that module and continuing without it only leads to errors:
#Requires -Version 3.0 -Modules Pscx The function is then declared using a Pascal case name that uses an approved verb along with a singular noun. Comment based help is provided just inside the function declaration. This isn’t the only location where comment based help can be specified at, but it’s my preferred location for it.
Click here to be redirected to the original post of this article on the author’s blog site where you can read the remainder of the article.
µ
Related Articles
Find What Wakes a Windows PC With Get-WinEvent
A PC that turns itself on at night leaves a record in the System log every time it does. Windows writes one event when the PC …
Read moreFind Free Azure CIDR Blocks with PowerShell
Suppose the network team assigns 10.172.0.0/16 to an Azure landing zone. You need to divide it into correctly aligned virtual …
Read moreHow to Toggle Logon Restrictions for AD Accounts
Written by Tino JR This script will allow an administrator to enable or disable logon restrictions for an Active Directory …
Read more