为什么我的函数返回空值

时间:2015-03-10 21:14:25

标签: powershell

所以我有以下代码,我想知道为什么最后3个值返回System.Collections.DictionaryEntry

    $count = 1
Function CreateHash($name, $address, $city, $state, $zip){

    return @{"name" = $name; "address" = $address;"city" = $city;"state" = $state; "zip" = $zip}

}
while ($count -lt 6){
    Write-host "This program will ask the user for the names and \n some other information about these people!"
    $name = Read-Host "Please enter the name of person $count"
    $address = Read-Host "Please enter the address of person $count"
    $city =  Read-Host "Please enter the city of person $count"
    $state = Read-Host "Please enter the state of person $count"
    $zip = Read-Host "Please enter the zip of person $count"
    $hash1 = CreateHash $name $address $city $state $zip
    Write-Host $hash1
    $count++ 
}

1 个答案:

答案 0 :(得分:2)

您使用错误的语法来调用CreateHash函数。

CreateHash($name, $address, $city, $state, $zip)

应该是:

CreateHash $name $address $city $state $zip

(参数值以空格分隔的方式传递给Powershell函数)