0
我对PowerShell处理函数参数的方式感到困惑。Powershell功能:管道和常用参数值之间的差别
,所以我有这个样本PS模块我只是做了测试,根据我的真实脚本:
function test {
[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact='Medium')]
param(
[Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [System.Management.Automation.PSObject]$InputObject
)
Begin {
}
Process {
Write-Host $InputObject
}
End {
}
}
Export-Modulemember -function test
保存为test.psm1 &进口,并做两个测试:
第一测试:
(get-process | select -first 5) | test
将与此回:
System.Diagnostics.Process (7zFM)
System.Diagnostics.Process (7zFM)
System.Diagnostics.Process (AcroRd32)
System.Diagnostics.Process (AcroRd32)
System.Diagnostics.Process (AESTSr64)
第二个测试:
test -InputObject (get-process | select -first 5)
将代替这个返回:当我使用一个变量来存储和转发数据
System.Diagnostics.Process (7zFM) System.Diagnostics.Process (7zFM) System.Diagn
ostics.Process (AcroRd32) System.Diagnostics.Process (AcroRd32) System.Diagnosti
cs.Process (AESTSr64)
同样的情况。
似乎那里碍手碍脚PowerShell将参数的差异,使用-InputObject参数当我回来的数据似乎失去其阵上下的格式在某种程度上...
它为什么做那?有没有办法改变这种行为?