Create powershell parameter default value is current directory

前端 未结 1 1139
孤街浪徒
孤街浪徒 2021-01-03 11:42

I\'m hoping to create a parameter who\'s default value is the \'current directory\' (.).

For example, the Path parameter of Get-Child

1条回答
  •  执念已碎
    2021-01-03 11:51

    Use PSDefaultValue attribute to define custom description for default value. Use SupportsWildcards attribute to mark parameter as Accept wildcard characters?.

    <#
    .SYNOPSIS
    Does something with paths supplied via pipeline.
    .PARAMETER Path
    Specifies a path to one or more locations. Wildcards are permitted. The default location is the current directory (.).
    #>
    Function Invoke-PipelineTest {
        [cmdletbinding()]
        param(
            [Parameter(Mandatory=$False,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
            [PSDefaultValue(Help='Description for default value.')]
            [SupportsWildcards()]
            [string[]]$Path='.'
        )
    }
    

    0 讨论(0)
提交回复
热议问题