VMware Cloud Community
StephenMoll
Expert
Expert
Jump to solution

Output from commandlets joining together out of sequence.

 

I am finding when I run this portion of PowerCLI:

#
Write-Host " `n--------------------------------------------------------------`n ESXi.set-shell-interactive-timeout `n--------------------------------------------------------------"
#
Get-VMHost | Get-AdvancedSetting -Name UserVars.ESXiShellInteractiveTimeOut | select Entity, Type, Value

#
Write-Host " `n--------------------------------------------------------------`n ESXi.set-shell-timeout `n--------------------------------------------------------------"
#
Get-VMHost | Get-AdvancedSetting -Name UserVars.ESXiShellTimeOut | select Entity, Value

#
Write-Host " `n--------------------------------------------------------------`n ESXi.TransparentPageSharing-intra-enabled `n--------------------------------------------------------------"
#
Get-VMHost | Get-AdvancedSetting -Name Mem.ShareForceSalting 
Get-VM | Get-AdvancedSetting -Name sched.mem.pshare.salt 

 

The output looks like this:

--------------------------------------------------------------
 ESXi.set-shell-interactive-timeout 
--------------------------------------------------------------

 
--------------------------------------------------------------
 ESXi.set-shell-timeout 
--------------------------------------------------------------
Entity       Type Value
------       ---- -----
10.0.0.1   VMHost     0
10.0.0.2   VMHost     0
10.0.0.1              0
10.0.0.2              0
 
--------------------------------------------------------------
 ESXi.TransparentPageSharing-intra-enabled 
--------------------------------------------------------------
10.0.0.1   VMHost     2
10.0.0.2   VMHost     2
 

 

So the output of the commandlet getting the ESXiShelIInteractiveTimeout value is being added into the table after the write-host commandlet that follows it. I have occasionally seen the output of all three commandlets joined together in the third table at the bottom. 

 

Why does this happen and how do I prevent it?

 

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You are confusing the PS output engine by doing Select-Object with different properties.
You can reset the output engine by doing a Out-Default after each Select-Object.

#
Write-Host " `n--------------------------------------------------------------`n ESXi.set-shell-interactive-timeout `n--------------------------------------------------------------"
#
Get-VMHost | Get-AdvancedSetting -Name UserVars.ESXiShellInteractiveTimeOut | Select-Object Entity, Type, Value | Out-Default
#
Write-Host " `n--------------------------------------------------------------`n ESXi.set-shell-timeout `n--------------------------------------------------------------"
#
Get-VMHost | Get-AdvancedSetting -Name UserVars.ESXiShellTimeOut | Select-Object Entity, Value | Out-Default

#
Write-Host " `n--------------------------------------------------------------`n ESXi.TransparentPageSharing-intra-enabled `n--------------------------------------------------------------"
#
Get-VMHost | Get-AdvancedSetting -Name Mem.ShareForceSalting


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

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

You are confusing the PS output engine by doing Select-Object with different properties.
You can reset the output engine by doing a Out-Default after each Select-Object.

#
Write-Host " `n--------------------------------------------------------------`n ESXi.set-shell-interactive-timeout `n--------------------------------------------------------------"
#
Get-VMHost | Get-AdvancedSetting -Name UserVars.ESXiShellInteractiveTimeOut | Select-Object Entity, Type, Value | Out-Default
#
Write-Host " `n--------------------------------------------------------------`n ESXi.set-shell-timeout `n--------------------------------------------------------------"
#
Get-VMHost | Get-AdvancedSetting -Name UserVars.ESXiShellTimeOut | Select-Object Entity, Value | Out-Default

#
Write-Host " `n--------------------------------------------------------------`n ESXi.TransparentPageSharing-intra-enabled `n--------------------------------------------------------------"
#
Get-VMHost | Get-AdvancedSetting -Name Mem.ShareForceSalting


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

Reply
0 Kudos
StephenMoll
Expert
Expert
Jump to solution

Super! LucD. That has helped. It sorted out some output from further down the code as well.

Why does the PS output engine get confused? 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

It uses the 1st Select-Object and assumes that all your following Select-Object cmdlets will have the same number of properties.
And it combines those 2 together, as you noticed.
With Out-Default you ask in fact for a reset, and the output engine forgets everything it has "seen" before.


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

Reply
0 Kudos
StephenMoll
Expert
Expert
Jump to solution

OK, that sounds like a deliberate design feature and quite useful. I don't know why I haven't discovered this before.

Thanks for the help.

Reply
0 Kudos