Powershell V2.0 error:Cannot bind parameter 'FilterScript'
Powershell V2.0 error:Cannot bind parameter 'FilterScript'
我正在尝试在 Powershell 中创建字典。这是脚本,我正在处理,
$environmentId = "Test"
$Dictionary = New-Object "System.Collections.Generic.Dictionary``2[System.String,System.String]"
$xml = [xml] (Get-Content "deploy.config")
$xml.SelectNodes("descendant::configuration/environment[@id='$($environmentId)']/descendant::text()[normalize-space()]") | ? Value | % {
$Dictionary.Add($_.ParentNode.ToString(), $_.Value)
}
write-output $Dictionary
此脚本适用于 Powershell 版本 4.0。但目前我们使用的是 2.0 版。当我 运行 这个脚本在 2.0 版本上时,抛出以下错误,
Where-Object : Cannot bind parameter 'FilterScript'. Cannot convert the "Value" value of type "System.String" to type "System.Management.Automation.ScriptBlock".
At C:\Users\pwsp_kkumar\Desktop\dictionary.ps1:6 char:129
+ $xml.SelectNodes("descendant::configuration/environment[@id='$($environmentId)']/descendant::text()[normalize-spa
ce()]") | ? <<<< Value | % {
+ CategoryInfo : InvalidArgument: (:) [Where-Object], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WhereObjectCommand
有人可以向我推荐 Powershell 2.0 版等效命令,以修复上述错误。谢谢。
问题出在管道的这一部分:
? Value
如果您要确保值 属性 不为空,您可以使用
? {$_.Value}
这应该没有问题。它还匹配您稍后添加的内容 ($_.Value).
我正在尝试在 Powershell 中创建字典。这是脚本,我正在处理,
$environmentId = "Test"
$Dictionary = New-Object "System.Collections.Generic.Dictionary``2[System.String,System.String]"
$xml = [xml] (Get-Content "deploy.config")
$xml.SelectNodes("descendant::configuration/environment[@id='$($environmentId)']/descendant::text()[normalize-space()]") | ? Value | % {
$Dictionary.Add($_.ParentNode.ToString(), $_.Value)
}
write-output $Dictionary
此脚本适用于 Powershell 版本 4.0。但目前我们使用的是 2.0 版。当我 运行 这个脚本在 2.0 版本上时,抛出以下错误,
Where-Object : Cannot bind parameter 'FilterScript'. Cannot convert the "Value" value of type "System.String" to type "System.Management.Automation.ScriptBlock".
At C:\Users\pwsp_kkumar\Desktop\dictionary.ps1:6 char:129
+ $xml.SelectNodes("descendant::configuration/environment[@id='$($environmentId)']/descendant::text()[normalize-spa
ce()]") | ? <<<< Value | % {
+ CategoryInfo : InvalidArgument: (:) [Where-Object], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WhereObjectCommand
有人可以向我推荐 Powershell 2.0 版等效命令,以修复上述错误。谢谢。
问题出在管道的这一部分:
? Value
如果您要确保值 属性 不为空,您可以使用
? {$_.Value}
这应该没有问题。它还匹配您稍后添加的内容 ($_.Value).