2

I have a problem that I do not understand. I am having a function that looks:

Function hashTable
{
    Param($release)

    $releaseArray = @()
    if (![string]::IsNullOrWhitespace($release))
    {
        $releaseArray = $release.split("{|}", [System.StringSplitOptions]::RemoveEmptyEntries)
        $releaseArray.gettype() | Select-Object Name
        if($releaseArray.Count -gt 0) {
            $namePathArray = @{}
            foreach($namePath in $releaseArray) {
                $splitReleaseArray = $namePath.split("{,}", [System.StringSplitOptions]::RemoveEmptyEntries)
                $namePathArray.add($splitReleaseArray[0], $splitReleaseArray[1])
            }

            #here it echos propper hashtable

            $namePathArray.gettype() | Select-Object Name
            if($namePathArray.Count -gt 0) {
                #here it echos propper hashtable as well
                return $namePathArray
            }
        }
    }
}

but when I call this function im getting an array not a hashtable that looks like:

Name
----
String[]
test
reorder

example input param: -release "reorder,c:\Repo\App|test,test"

And I am wondering if I'm missing something?

2
  • What $releaseArray.gettype() | Select-Object Name and $namePathArray.gettype() | Select-Object Name in your code supposed to do? Commented May 29, 2016 at 9:43
  • This is somethi ng for earlier debbuging Commented May 29, 2016 at 9:55

1 Answer 1

3

You effectively pollute the output stream with the GetType() |Select Name statements. Remove them, or use Write-Host to display the type names instead:

Function hashTable
{
    Param($release)

    $releaseArray = @()
    if (![string]::IsNullOrWhitespace($release))
    {
        $releaseArray = $release.split("{|}", [System.StringSplitOptions]::RemoveEmptyEntries)
        Write-Host ($releaseArray.gettype() | Select-Object -Expand Name)
        if($releaseArray.Count -gt 0) {
            $namePathArray = @{}
            foreach($namePath in $releaseArray) {
                $splitReleaseArray = $namePath.split("{,}", [System.StringSplitOptions]::RemoveEmptyEntries)
                $namePathArray.add($splitReleaseArray[0], $splitReleaseArray[1])
            }

            #here it echos propper hashtable

            Write-Host ($namePathArray.gettype() | Select-Object -Expand Name)
            if($namePathArray.Count -gt 0) {
                #here it echos propper hashtable as well
                return $namePathArray
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.