0
votes

So I have the following code and am wondering why the last 3 values are returning 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
Which last three values? $null where/when? What is happening exactly? - Etan Reisner
As you can see it has been updated. Now it's outputting System.Collections.DictionaryEntry for each variable at the Write-Host $hash1 line - OysterMaker

1 Answers

2
votes

You're using the wrong syntax to call the CreateHash function.

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

should be:

CreateHash $name $address $city $state $zip

(parameter values are passed to Powershell functions as space-separated)