I create a small script for accepting a Users ID, First Name, Last Name and then adding that data to a hash table. The problem I have is when I display my hashtable to says the value of the user is System.Object. What am I doing wrong?
$personHash = @{}
$userID=""
$firstname=""
$lastname=""
While([string]::IsNullOrWhiteSpace($userID))
{
$userID = Read-Host "Enter ID"
}
While([string]::IsNullOrWhiteSpace($firstname))
{
$firstname = Read-Host "Enter First Name"
}
While([string]::IsNullOrWhiteSpace($lastname))
{
$lastname = Read-Host "Enter Last Name"
}
$user = New-Object System.Object
$user | Add-Member -type NoteProperty -Name ID -value $userID
$user | Add-Member -type NoteProperty -Name First -value $firstname
$user | Add-Member -type NoteProperty -Name Last -Value $lastname
$personHash.Add($user.ID,$user)
$personHash
$useras aSystem.Object. What are you expecting?$personHash[$user.ID]or$personHash['NameYouEntered']. You seeSystem.Objectbecause the hashtable contains an object of that type as the value for that entry. It's a placeholder that says "There's an object here, but it's too complex to display."