'Return type PSObject not right

I have a situation regarding PSObject. Thing is when I write only the same PSObject in different script it returns what it should.

$returnobject = New-Object -TypeName psobject
$returnobject | Add-Member -MemberType NoteProperty -Name LocalITMail -Value "what"
$returnobject | Add-Member -MemberType NoteProperty -Name LocationSufix -Value "wont you "
$returnobject | Add-Member -MemberType NoteProperty -Name Webproxy -Value "work"
return $returnobject

I get this

enter image description here

which is good.

But when I call the function from bigger script the return type is not as the form above and I cannot access its properties.

Example:
enter image description here

What am I doing wrong, is there a way on how to return the PSObject type so I don't get this @{...} output? Thanks.



Solution 1:[1]

When working with Class in powershell and calling a function/method the PSObject is not a String. This was my problem here.

@codaamok comment helped me here

Didnt know that powershell mehtod/function allows the return of PSObject

   [PSobject] GetLocation($User, $LocationList) {
    #create return object since we are returning more values. 
    $returnobject = New-Object -TypeName psobject

    foreach ($item in $LocationList) {
        if ($item.zzlocat -eq $user.l -or $item.l -eq $user.l) {
           $returnobject | Add-Member -MemberType NoteProperty -Name LocalITMail -Value $item.Mail 
           $returnobject | Add-Member -MemberType NoteProperty -Name LocationSufix -Value $item.'sAMAccount Abbrevations (5th and 6th characters)' 
           $returnobject | Add-Member -MemberType NoteProperty -Name Webproxy -Value $item.sec_WWGG_WebSecurity_Office 
        }
    }
    return $returnobject
    Write-output "$($this.TimeSTAMP)[Helper]::GetLocation -> Found Location from User" | Out-File $this.Workflow -Append
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 iAlucard