gpt4 book ai didi

Powershell:未填充参数/参数

转载 作者:行者123 更新时间:2023-12-04 15:02:02 24 4
gpt4 key购买 nike

我有一个 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 提示向我询问这些参数,然后给我同样的错误,关于它们没有被传入。

最佳答案

除非您使用 ValueFromRemainingArguments 属性标记参数(指示 cmdlet 参数是否接受与此参数关联的所有剩余命令行参数),否则 Args 将被“禁用”。如果您只需要参数 count 调用特殊变量:

$PSBoundParameters.Count

关于Powershell:未填充参数/参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11009834/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com