我有一个关于PSObject的情况。问题是,当我只在不同的脚本中编写相同的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我明白了

这很好。
但是,当我从更大的脚本调用函数时,返回类型不是上面的表单,我不能访问它的属性。
示例:

我做错了什么,有没有办法返回PSObject类型,这样我就不能得到这个@{...}输出?谢谢。
发布于 2022-05-06 08:43:40
在powershell中使用类并调用函数/方法时,PSObject不是字符串。这是我的问题。
@codaamok评论帮了我这个忙
不知道powershell mehtod/函数允许返回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
}https://stackoverflow.com/questions/72138287
复制相似问题