Skip to content

Instantly share code, notes, and snippets.

@gp42
Last active July 9, 2018 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gp42/62f642b7a46c91900d392f4bf4f028f0 to your computer and use it in GitHub Desktop.
Save gp42/62f642b7a46c91900d392f4bf4f028f0 to your computer and use it in GitHub Desktop.
CmdletBinding - makes a function work like a compiled cmdlet.
# The CmdletBinding attribute is an attribute of functions that makes them operate
# like compiled cmdlets that are written in C#, and it provides access to features of cmdlets.
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_cmdletbindingattribute?view=powershell-6
[CmdletBinding()]
param(
# Input params
[string]${inputParam},
# Example with validator and help message
[Parameter(HelpMessage="Output directory")]
[ValidateScript({$_ -notmatch "\.exe$"})]
[string]${outputDir} = 'out',
# Environment Variable usage
[string] $param = $env:PARAM,
# Switch param
[switch] $someFlag
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment