Skip to content

Instantly share code, notes, and snippets.

@shane-edmonds
Created May 12, 2013 06:35
Show Gist options
  • Save shane-edmonds/5562649 to your computer and use it in GitHub Desktop.
Save shane-edmonds/5562649 to your computer and use it in GitHub Desktop.
PowerShell Function Template
function new-template {
<#
.SYNOPSIS
Brief description of what the function does
.DESCRIPTION
A better description
.NOTES
Function Name : new-template
Author : Adam Stone
Requires : PowerShell V2
.LINK
http://adadmin.blogspot.com/
.EXAMPLE
Simple usage
PS C:\> new-template -args values
.EXAMPLE
Simple usage
PS C:\> new-template -args values values etc
.PARAMETER first
A description of the first parameter
.PARAMETER targetdomain
A description of the sedond parameter
#>
#parameter validataion
param (
#define the position of the parameter if required, specify if it is mandatory, and give a help message if anything is incorrect
[Parameter(Position=0, Mandatory=$true,HelpMessage="Enter the source Domain DNS name (eg domain.com) of the OU Structure")]
#add an alias to accept different names through the pipeline
[alias("other")]
#choose one of these if required
#make sure the option is not null or empty
#[validatenotnullorempty()]
#valadate the input against a regex pattern
#[validatepattern("regex")]
#valadate the input against defined set of attributes
#[validateset("one","two")]
#define type if necessary and what the default value will be if not manditory
[string] $first = "abcde"
,
#new parameter after the comma
[Parameter(Mandatory=$false)]
[alias("out")]
[string] $fileout = "none"
)
#the processes the function will complete
process {
#do stuff!
}
}#end function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment