[英]Return type PSObject not right
I have a situation regarding PSObject.我有一个关于 PSObject 的情况。 Thing is when I write only the same PSObject in different script it returns what it should.
事情是当我在不同的脚本中只写同一个 PSObject 时,它会返回它应该返回的内容。
$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我明白了
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.但是当我从更大的脚本调用 function 时,返回类型与上面的形式不同,我无法访问它的属性。
What am I doing wrong, is there a way on how to return the PSObject type so I don't get this @{...}
output?我做错了什么,有没有办法返回 PSObject 类型,这样我就不会得到这个
@{...}
output? Thanks.谢谢。
When working with Class in powershell and calling a function/method the PSObject is not a String.在 powershell 中使用 Class 并调用函数/方法时,PSObject 不是字符串。 This was my problem here.
这是我的问题。
@codaamok comment helped me here @codaamok 评论在这里帮助了我
Didnt know that powershell mehtod/function allows the return of PSObject不知道 powershell 方法/函数允许返回 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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.