我有一个 PowerShell 脚本:
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 shell)运行,并得到
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
我传递的任何参数都会得到完全相同的错误,如果我尝试使用命名参数也会出现相同的错误。
什么会导致参数不能传入?
更新:PowerShell ISE 使用 GUI 提示向我询问这些参数,然后给我同样的错误,关于它们没有被传入。