Forum Discussion

senglory's avatar
senglory
Copper Contributor
Aug 05, 2024
Solved

Why do I get name printed 3 times instead of 2?

Hi ,  here's my code:         Add-Type -AssemblyName System.Web $fileInGpx = "b.gpx" [hashtable]$wptsUnique = @{} [xml]$xml = Get-Content -Path $fileInGpx -Encoding UTF8 function trySetWp...
  • MMeyer260's avatar
    Aug 05, 2024

    senglorychange line 34 to:

    trySetWptColor $wpt $wptExisting

    Passing multiple arguments to a function in PowerShell should not use commas to separate them, and function calls should not use parentheses. By using a comma, you are actually passing two variables merged into a single array ($wpti) whose first element is of type System.Xml.XmlElement and whose second element is a hashtable. The second variable ($wptExisting) is null. On line 12, Write-Host was writing all elements of the array that had a property called Name.