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

创建powershell参数默认值为当前目录,powershell,powershell-3.0,Powershell,Powershell 3.0,我希望创建一个默认值为“当前目录”的参数() 例如,Get ChildItem的Path参数: PS> Get-Help Get-ChildItem -Full -路径 指定一个或多个位置的路径。允许使用通配符。默认位置为当前位置 目录(.) 我创建了一个带有Path参数的函数,该参数接受来自管道的输入,默认值为: <# .SYNOPSIS Does something with paths supplied via pipeline. .PARAMETER Path Specif

我希望创建一个默认值为“当前目录”的参数(

例如,
Get ChildItem
Path
参数:

PS> Get-Help Get-ChildItem -Full
-路径 指定一个或多个位置的路径。允许使用通配符。默认位置为当前位置 目录(.)

我创建了一个带有
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 {}
}
-路径 指定一个或多个位置的路径。允许使用通配符。默认位置是当前目录(.)

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


顺便问一下,在哪里设置
接受通配符属性?

使用
PSDefaultValue
属性定义默认值的自定义描述。使用
SupportsWildcards
属性将参数标记为
接受通配符?


函数调用管道测试{
[cmdletbinding()]
param(
[参数(必需=$False,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
[PSDefaultValue(Help='Description for default value.'')]
[SupportsWildcards()]
[string[]]$Path='。'
)
}

您确定这不仅仅是函数内部魔法和文本默认值“当前目录”吗?(我认为这并没有那么愚蠢,而且是明确的,但我也认为您可能无法在powershell中直接复制。)我认为这是可能的,但我觉得这似乎有些草率。该值(
Current directory
)是否会根据Windows本地化而更改?我假设字符串是本地化的,而不管它是如何在内部实现的。也就是说,我不希望与内部使用的值进行比较。我希望使用“wasavalidvaluegived”测试,因为
$null
在这里没有意义。我想微软不会费心更新文档吧*叹气*。我认为这是“是的”。)@AnsgarWiechers我不在微软工作,所以我不能为他们负责。也许,你们可以填一下票来打扰他们。
<#
.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 {}
}
PS> Get-Help Invoke-PipelineTest -Full
    Required?                    false
    Position?                    1
    Default value                .
    Accept pipeline input?       true (ByValue, ByPropertyName)
    Accept wildcard characters?  false