Skip to content

Instantly share code, notes, and snippets.

@CN-CODEGOD
Created November 22, 2024 19:53
Show Gist options
  • Save CN-CODEGOD/7057854cfe45cdd0b81b8b9ed7c78216 to your computer and use it in GitHub Desktop.
Save CN-CODEGOD/7057854cfe45cdd0b81b8b9ed7c78216 to your computer and use it in GitHub Desktop.
powershell 参数类型集合
1.parameterset
nction Measure-Lines {
[CmdletBinding(DefaultParameterSetName = 'Path')]
param (
[Parameter(Mandatory, ParameterSetName = 'Path', Position = 0)]
[Parameter(Mandatory, ParameterSetName = 'PathAll', Position = 0)]
[string[]]$Path,
[Parameter(Mandatory, ParameterSetName = 'LiteralPathAll', ValueFromPipeline)]
[Parameter(Mandatory, ParameterSetName = 'LiteralPath', ValueFromPipeline)]
[string[]]$LiteralPath,
[Parameter(ParameterSetName = 'Path')]
[Parameter(ParameterSetName = 'LiteralPath')]
[switch]$Lines,
[Parameter(ParameterSetName = 'Path')]
[Parameter(ParameterSetName = 'LiteralPath')]
[switch]$Words,
[Parameter(ParameterSetName = 'Path')]
[Parameter(ParameterSetName = 'LiteralPath')]
[switch]$Characters,
[Parameter(Mandatory, ParameterSetName = 'PathAll')]
[Parameter(Mandatory, ParameterSetName = 'LiteralPathAll')]
[switch]$All,
[Parameter(ParameterSetName = 'Path')]
[Parameter(ParameterSetName = 'PathAll')]
[switch]$Recurse
)
2.validateset
[ValidateSetAttribute("Steve")]
[ValidateSetAttribute("Steve","Mary")]
3.$psscmdlet
常用:
$psscmdlet.parametersetName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment