创建powershell参数默认值为当前目录

Create powershell parameter default value is current directory

我希望创建一个默认值为 'current directory' (.) 的参数。

例如Get-ChildItemPath参数:

PS> Get-Help Get-ChildItem -Full

-Path Specifies a path to one or more locations. Wildcards are permitted. The default location is the current directory (.).

    Required?                    false
    Position?                    1
    Default value                Current directory
    Accept pipeline input?       true (ByValue, ByPropertyName)
    Accept wildcard characters?  true

我创建了一个带有 Path 参数的函数,它接受来自管道的输入,默认值为 .:

<#
.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)]
        [string[]]$Path='.'
    )
    BEGIN {}
    PROCESS {
      $Path | Foreach-Object {
        $Item = Get-Item $_
        Write-Host "Item: $Item"
      }
    }
    END {}
}

但是,. 未被解释为帮助中的 'current directory':

PS> Get-Help Invoke-PipelineTest -Full

-Path Specifies a path to one or more locations. Wildcards are permitted. The default location is the current directory (.).

    Required?                    false
    Position?                    1
    Default value                .
    Accept pipeline input?       true (ByValue, ByPropertyName)
    Accept wildcard characters?  false

Path 参数的默认值设置为当前目录的正确方法是什么?

顺便说一下,Accept wildcard character 属性 在哪里设置?

使用PSDefaultValue 属性定义默认值的自定义说明。使用 SupportsWildcards 属性将参数标记为 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='.'
    )
}