我希望创建一个参数,其默认值为“当前目录”(
例如,
然而,在帮助文档中,
.
)。例如,
Get-ChildItem
的Path
参数: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 {}
}
然而,在帮助文档中,
.
并不被解释为“当前目录”。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
参数的默认值设置为当前目录?
顺便问一下,接受通配符字符
属性应该在哪里设置?
当前目录
这个值会根据Windows本地化而改变吗? - craig$null
在这里没有意义。 - Etan Reisner