更新时间:2023-11-24 09:35:28
不幸的是,-PipelineVariable
不适用于Remove-VBComments
之类的脚本cmdlet.这就是为什么将Select-Object
运行成功的原因-这是C#cmdlet.但是您实际上并不需要它,因为foreach循环中的$_
具有$files
变量中应包含的所有信息.更新代码看起来像
Unfortunately -PipelineVariable
doesn't work with script cmdlets like Remove-VBComments
. That's why moving if to Select-Object
worked - it's a C# cmdlet. But you don't actually need it since $_
in the foreach loop has all of the information that would have been in the $files
variable. The update code would look something like
$filesToStripComment |
Remove-VBComments |
&{Process{
$UncommentedFileName = $_.UncommentedFileName
Get-Content -Path $UncommentedFileName |
Measure-Object -Line |
Select-Object -Property `
@{n="FileName";e={$UncommentedFileName}},
@{n="LoC";e={$_.Lines}} `
} }