当PowerShell参数不是
问题描述:
PowerShell参数是一个空字符串我想通过NodeJS参数中给出的字符串搜索文件。当PowerShell参数不是
param(
[switch]$raw,
[string]$input
)
[string]$file = "*.log"
if($raw) { $file = ".\raws\*.log" }
Get-ChildItem -Recurse -Include $file | select-string $input
我在做什么错?
答
感谢@TessellatingHeckler指出$input
是一个保留/自动变量,因此不能像这样使用。
'$ input'是一个[自动变量](https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/about/about_automatic_variables),你不应该使用它在您的代码中的名称。不知道这是为什么它突破,但它肯定是误导。 – TessellatingHeckler
那就是@TessellatingHeckler。非常感谢你。 – Farcrada
[$ \ _和\ [参数(ValueFromPipeline = $ true)\]]之间的奇怪差异可能重复(http://*.com/questions/13502949/strange-difference-between-and-parametervaluefrompipeline-true) –