当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 

的问题是,我得到了错误$input是空的: PowerShell says $input is empty.

我在做什么错?

+4

'$ input'是一个[自动变量](https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.core/about/about_automatic_variables),你不应该使用它在您的代码中的名称。不知道这是为什么它突破,但它肯定是误导。 – TessellatingHeckler

+0

那就是@TessellatingHeckler。非常感谢你。 – Farcrada

+0

[$ \ _和\ [参数(ValueFromPipeline = $ true)\]]之间的奇怪差异可能重复(http://*.com/questions/13502949/strange-difference-between-and-parametervaluefrompipeline-true) –

感谢@TessellatingHeckler指出$input是一个保留/自动变量,因此不能像这样使用。