I have the following code which reads an XML file, outputs the nodes and presents the user with a prompt to input a choice. For some reason, no matter what I put in, it always says "Invalid Choice". What am I doing wrong?
$buildsFile = [System.Xml.XmlDocument](Get-Content "$($config.remotebuildspath)/builds.xml");
$builds = $buildsFile.builds;
$i = 0
$buildHash = @{}
Write-Host "Available Builds: " -ForeGroundColor Green
ForEach ($buildVersion in $builds.ChildNodes) {
$i++
Write-Host "(" -NoNewline -ForeGroundColor Green
Write-Host $i -NoNewline
Write-Host ") $($buildVersion.LocalName)" -ForeGroundColor Green
$buildHash.add($i, $buildVersion.LocalName)
}
$isValid = $false
do {
Write-Host "Choose: " -NoNewline -ForeGroundColor Green
$choice = Read-Host
if ($buildHash.ContainsKey($choice)) {
$isValid = $true
} else {
Write-Host "Invalid Choice!" -ForeGroundColor Red
$isValid = $false
}
} while ($isValid -eq $false)
Write-Host "You picked ${$buildHash[$choice]}"
Debugger screenshots: