In this post I showed my Advanced Function template http://msmvps.com/blogs/richardsiddaway/archive/2011/05/13/powershell-module-construction.aspx
I’ve since modified it to add the parameter validation methods. I can never remember them all so decided putting them in the template was the easiest way forward.
001
002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 |
function aaaa-yyyyyy{
[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact="Medium Low High None", DefaultParameterSetName="XXXXX")] param ( [parameter(Position=0, Mandatory=$true, ParameterSetName="YYYYYYYYYY", ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, ValueFromRemainingArguments=$true, HelpMessage="Put your message here", Alias("CN", "ComputerName") )] [AllowNull()] [AllowEmptyString()] [AllowEmptyCollection()] [ValidateCount(1,10)] [ValidateLength(1,10)] [ValidatePattern("[A-Z]{2,8}[0-9][0-9]")] [ValidateRange(0,10)] [ValidateScript({$_ -ge (get-date)})] [ValidateSet("Low", "Average", "High")] [ValidateNotNull()] [ValidateNotNullOrEmpty()] [string]$computer="." ) BEGIN{}#begin PROCESS{ if ($psCmdlet.ShouldProcess("## object ##", "## message ##")) { }#process <# .SYNOPSIS
.DESCRIPTION
.PARAMETER <Parameter-Name>
.EXAMPLE
.INPUTS
.OUTPUTS
.NOTES
.LINK
#>
} |
One or two may not be right on a string parameter but they are there as a reminder not code that will run
By: Xavier C on May 30, 2011 at 7:27 pm
Cool! Added to my snippets!
Thanks Richard!