【发布时间】:2015-08-25 17:29:18
【问题描述】:
我有一个从哈希表返回值的简单脚本:
param
(
[Parameter(Mandatory = $true)]
[string]$Name
)
function getvalues ($Name) {
$nameList= @{"CFT"=@{"name1"="text1"; "name2"="text2"}}
#return $nameList[$Name]
return ,$nameList
}
$Values = getvalues($Name)
Write-Debug "DEBUG: Name1 = "$Values["name1"]
Write-Debug "DEBUG: Name2 = "$Values["name2"]
当我运行它时,我收到以下错误:
Write-Debug : A positional parameter cannot be found that accepts argument '$null'.
At C:\MSFT\add-test.ps1:21 char:2
+ write-Debug "DEBUG: Name1 = "$Values["name1"]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Write-Debug], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.WriteDebugCommand
Write-Debug : A positional parameter cannot be found that accepts argument '$null'.
At C:\MSFT\add-test.ps1:22 char:2
+ write-Debug "DEBUG: Name2 = "$Values["name2"]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Write-Debug], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.WriteDebugCommand
【问题讨论】:
-
您应该编辑您的问题以修复代码格式。
标签: function powershell hashtable return-value