繁体   English   中英

Powershell:将系统密钥作为参数传递

[英]Powershell: pass system key as a argument

我想传递-Unique作为选择字符串的参数

param(
    $y="CAR"
    $parameter=""
)
get-childitem -r -i "*.txt"| select-string "TABLE FILE $y" | Select-Object filename,path $parameter

但是每当我尝试传递参数时,都会出现以下错误

powershell : Select-Object : A positional parameter cannot be found that accepts argument '-Unique'.
At line:1 char:1
+ powershell -ExecutionPolicy ByPass -File x.ps1 -parameter '-Unique'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Select-Object :...ment '-Unique'.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

At C:\Users\aravikumar\Downloads\x.ps1:5 char:62
+ ... elect-string "TABLE FILE $y" | Select-Object filename,path $parameter
+                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand

如果可能,还希望传递多个系统密钥,例如-unique -simplesearch -casesensitive

您不能像这样将开关作为字符串参数传递。 您需要使用一种称为“喷涂”的技术。 请参阅help about_splattinghttps://msdn.microsoft.com/zh-cn/powershell/reference/5.1/microsoft.powershell.core/about/about_splatting

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM