My PowerShell Function Template
function Verb-Noun
{
<# .synopsis .description .parameter param1 param2 .example .notes created by: name - email@address.com copyright (c) 2017. all rights reserved. this code is made available as is, without warranty of any kind. the entire risk use or results from remains with user. #>
[CmdletBinding(SupportsShouldProcess = $true)]
Param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $false)][String]$Param
)
trap{Write-Host -f Red "$($_.Exception.Message)"; return $false}
#This is where you do things
#This is the end
return $true # or returb $object
}
This function template is designed for scenarios where you do not intend to accept intake from the pipeline, but rather return a true or false, or return an object.
My style of PowerShell is probably thought of as pretty old school these days, and tbh, probably a little out dated. But, it does the job for the most part. This template is where I start from for basic functions. I don't bother with pipeline intake, or with more detailed error handling and just throw a basic trap in so that any errors aren't overtly ugly...
This template is just a good starting point... where things go from here is the fun part!