Print Parent object property

This post was originally published on this site

This is a pretty basic query I believe but somehow I can’t get my head around it.  I want to extract the list of syslog servers configured on Esxi hosts . The powercli command I used is :


Get-VMHost | Get-AdvancedSetting | ?{$_.Name -Like “*”}  | Select-Object -Property Value


Query 1  :  How do i reference the parent object property ? I intend to Print the Esxi Hostname in one column and the list of syslog servers configured in 2nd column. I tried using calculated properties but it didn’t work . So this is what I used :


Get-VMHost | Get-AdvancedSetting | ?{$_.Name -Like “*”}  | Select-Object -Property Value , @{Name = ‘WithParens’;Expression = {“( $($_.Name) )”}}


Some Progress …..


I was able to refer the immediate parent object but not the outermost parent ( not sure if that is the correct lingo )


Get-VMHost | Get-AdvancedSetting | ?{$_.Name -Like “*”}  | Select-Object -Property Value , @{Name = ‘Parent’;Expression = {“( $($_.Name) )”}}


Also tried another approach with a foreach block but it just hangs :


foreach($ho in Get-VMHost){ Select @{$_.Name},@{N=’syslog’;E={$ho.Name | Get-AdvancedSetting | ?{$_.Name -Like “*”} | Select-Object -Property Value}}


What am I doing wrong ? What is the gold standard way of referencing nested properties ?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.