我有一个PowerShell脚本:PowerShell的:参数数量/ PARAMS不填充
param (
[Parameter(Mandatory=$true)][string]$input,
[Parameter(Mandatory=$true)][string]$table
)
Write-Host "Args:" $Args.Length
Get-Content $input |
% { [Regex]::Replace($_, ",(?!NULL)([^,]*[^\d,]+[^,]*)", ",'`$1'") } |
% { [Regex]::Replace($_, ".+", "INSERT INTO $table VALUES (`$1)") }
的Write-Host part
用于调试。
我运行它.\csvtosql.ps1 mycsv.csv dbo.MyTable
(从PowerShell的外壳),并获得
Args: 0
Get-Content : Cannot bind argument to parameter 'Path' because it is an empty s
tring.
At C:\temp\csvtosql.ps1:7 char:12
+ Get-Content <<<< $input |
+ CategoryInfo : InvalidData: (:) [Get-Content], ParameterBinding
ValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAl
lowed,Microsoft.PowerShell.Commands.GetContentCommand
我得到完全相同的错误与我传递任何参数,也同样的错误,如果我尝试使用命名参数。
什么会导致参数不被传入?
UPDATE:PowerShell的ISE问我这些参数使用GUI提示,然后给了我同样的错误对他们没有被传递
好的,'$ args'只是为了调试,但是你是对的,根据其他人的回复他们根本无法工作。 –
现在'$ input'是特殊的是我的问题的原因。非常感谢! –