Lerch Web Wiki

Random, erratic, no responsibility is taken for the correctness of this information

User Tools

Site Tools


powershell:basics:cmdletbinding

CmdletBinding

cmdlet-binding.ps1
#region Parameter
[cmdletBinding(SupportsShouldProcess=$true)]
param(
)
 
#endregion
 
$Files = Get-ChildItem
foreach ($File in $Files){
	if($pscmdlet.ShouldProcess($File.FullName, "Delete File")){
		Remove-Item -LiteralPath $File.FullName
	}
}
cmdlet-binding-ParameterSets.ps1
#region Parameter
[cmdletBinding(DefaultParametersetname='Set1')]
param(
    [Parameter(ParameterSetName='Set1')][Parameter(ParameterSetName='Set2')]$Para1,
    [Parameter(ParameterSetName='Set2')]$Para2,
    [Parameter(ParameterSetName='Set3')]$Para3,
    [Parameter(ParameterSetName='Set4')]$Para4
)
 
#endregion
 
switch ($pscmdlet.ParameterSetName)
{
    'Set1' {'set1 called'}
    {$_ -in 'Set2','Set3'} {$pscmdlet.ParameterSetName + " called"}
    'Set4' {'set4 called'}
    Default {}
}
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
powershell/basics/cmdletbinding.txt · Last modified: 2017/02/21 11:00 by marcus