Created
November 6, 2023 15:55
-
-
Save Dimtemp/755073ea60bad8fc6cd00a477b1c4258 to your computer and use it in GitHub Desktop.
Simple template for a PowerShell function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Verb-Noun { | |
<# | |
.SYNOPSIS | |
Short description | |
.DESCRIPTION | |
Long description | |
.EXAMPLE | |
Verb-Noun | |
Example of how to use this cmdlet | |
.EXAMPLE | |
Verb-Nound -Param1 test | |
Another example of how to use this cmdlet | |
.NOTES | |
General notes | |
#> | |
[CmdletBinding()] | |
Param( | |
# Param1 help description | |
[Parameter(Mandatory=$true)] | |
[ValidateNotNull()] | |
[ValidateNotNullOrEmpty()] | |
[ValidateCount(0,5)] | |
[ValidateSet('Venus', 'Earth', 'Mars')] | |
[string]$Planet, | |
# Param2 help description | |
[AllowNull()] | |
[AllowEmptyCollection()] | |
[AllowEmptyString()] | |
[ValidateScript({$true})] | |
[ValidateRange(0,5)] | |
[int]$Param2, | |
# Param3 help description | |
[ValidatePattern('LON-\w{2,3}\d{1,2}')] | |
[ValidateLength(0,15)] | |
[String]$ComputerName, | |
[Parameter(Mandatory=$true, | |
HelpMessage='On or off')] # interactive helpmessage: use !? if this is a required parameter | |
[string]$Param4, | |
[switch]$Param5 | |
) | |
foreach($Computer in $ComputerName) { | |
$properties = [ordered]@{ | |
'Version' = 2; | |
'Model' = 'X' | |
} | |
$output = New-Object -TypeName PSObject -Property $properties | |
Write-Output $output | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment