I would really appreciate it if somebody could point out what I am doing wrong in passing parameters from a function back to the mainline code. I have a variable which has been successfully extracted in a function, but I cannot seem to pass that back to the mainline code
This is the code I am using:
function get-field ($field, $heading) { $fieldPos = $script:source.AllElements.InnerText.IndexOf($heading) +1 $field = $script:source.AllElements.InnerText[$fieldPos] # If states "Not Available", or contains a heading, process as if not found. if ($field -eq "Not Available ") {$fieldPos = 0} if ($field -eq $heading) {$fieldPos = 0} # Check that a valid entry was received if ($fieldPos -eq 0) { Write-Host "Warning:" $heading "was not found" } else { $field = $field.Trim() } return $field } get-field $email "Name" get-field $address "Address" I have verified that within the function, the $field and $heading parameters contain the correct information, so why aren't the $email and $address fields being populated?
$fieldbut dont save it anywhere when you call the funtction. Without knowing the function, does$email = get-field $email "Name"solve the problem?