GodfatherHTLF
Contributor
Contributor

powershell command output include host name

when i use the fallowing command it outputs the results, but doesn't tell me what host the results happened on.  How can i modify the command to display the name of the server/host that pairs w/ the output?

 

Get-VMhost | Get-AdvancedSetting -Name Syslog.global.logDirUnique | Set-AdvancedSetting -Value $True -Confirm:$False | ft -AutoSize

 

this is my output

GodfatherHTLF_0-1663597081033.png

 

I'd like another column that would state the server name.

Reply
0 Kudos
LucD
Leadership
Leadership

With a calculated property you can access the $_.Entity.Name value

Get-VMHost |
Get-AdvancedSetting -Name Syslog.global.logDirUnique |
Set-AdvancedSetting -Value $True -Confirm:$False |
Select @{N='VMHost';E={$_.Entity.Name}},Name,Value,Type,Description |
Format-Table -AutoSize


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
GodfatherHTLF
Contributor
Contributor

can we kind of break this down a bit, I'm kind of PowerShell dumb/noob.  

When the Get-VMHost command gets piped into the Get-AdvancedSettings command is that executed for each host like a for next loop, or are the values all cached in something like an array and executed all at once after all vmhosts are contacted?

Reply
0 Kudos
LucD
Leadership
Leadership

A PowerShell, and PowerCLI, cmdlet returns objects that are placed one-by-one in the pipeline.
That pipeline passes these objects, again one-by-one, to the next cmdlet in the chain.

A calculated property on a Select-Object cmdlet allows you to specify an expression (in the E part).
That expression can refer to a nested property, or can even a complete code block.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference