Demo-CmdLetBinding.ps1
<#PSScriptInfo .VERSION 1.0.0 .GUID 865406f6-992e-476a-8ef7-4a0d5a9ee60e .AUTHOR Frits van Drie (3-Link.nl) .COMPANYNAME 3-Link Opleidingen .COPYRIGHT free to use and distribute without modifications .TAGS .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES .PRIVATEDATA #> <# .DESCRIPTION Developed by 3-Link Opleidingen for training purposes only #> Param() <# .NOTES Filename: Demo-CmdLetBinding Date: 2022-04-07 Author: Frits van Drie (3-Link.nl) The CmdletBinding attribute is an attribute of functions that makes them operate like compiled cmdlets written in C#. It provides access to the features of cmdlets. .LINK Demo-Parameters.ps1 .LINK https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_cmdletbindingattribute #> Write-Warning 'This script is developed for demonstration. Open it in your code editor and run in step-by-step' BREAK #region: Functions #endregion Function Demo-WithoutCmdLetBinding { Param ( [string]$ComputerName = $env:COMPUTERNAME ) Write-Verbose "Demo-WithoutCmdLetBinding running on:" Write-Host $ComputerName } Help Demo-WithoutCmdLetBinding -ShowWindow cls; Demo-WithoutCmdLetBinding cls; Demo-WithoutCmdLetBinding -Verbose Function Demo-CmdLetBinding { [CmdletBinding()] Param ( [string]$ComputerName = $env:COMPUTERNAME ) Write-Verbose "Demo-CmdLetBinding running on:" Write-Host $ComputerName } Help Demo-CmdLetBinding -ShowWindow # ==> [<CommonParameters>] cls; Demo-CmdLetBinding cls; Demo-CmdLetBinding -Verbose Help about_CommonParameters -ShowWindow # '| More' does not work in ISE Function CmdletBindingArguments { [CmdletBinding( ConfirmImpact = 'LowMediumHigh', DefaultParameterSetName = 'Set1', HelpURI = 'https:help.me.now', SupportsPaging = $true, SupportsShouldProcess = $true, PositionalBinding = $true )] param() } Break #region Cleanup Demo Function Cleanup-Demo { param( $path ) try { Remove-Item $path -Recurse -Confirm:$false -Force -ea Stop Write-Host "Removed $path" -f Green return } catch { Write-Warning $error[0].Exception.Message } } Cleanup-Demo -path "FUNCTION:\Demo-WithoutCmdLetBinding" Cleanup-Demo -path "FUNCTION:\Demo-CmdLetBinding" Cleanup-Demo -path "FUNCTION:\CmdLetBindingArguments" #endregion |