The situation:  You want to ensure that an advanced setting is consistently applied through all of your VMs.

Getting Advanced Settings from all of your VMs… almost

You run this command in PowerCLI to find out which VMs are configured the way you want, and which need to be adjusted:

$AdvancedSettingName = 'isolation.tools.diskshrink.disable'
#(Could be anything, but this is the specific setting that I was working with)

Get-VM | Get-AdvancedSetting -Name $AdvancedSettingName

The output is simple enough, and for me the output was consistent – everything was “true”… but unfortunately, the results weren’t accurate because all of the VMs weren’t listed.

My problem was in assuming that it would always be either “true” or “false”, but it turns out that there is a third option:  “the advanced setting doesn’t exist for that object”.

That third option is the reason that I had an incomplete list. The output of Get-VM is passed as an input to Get-AdvancedSetting.  But the output of Get-AdvancedSetting is an advanced setting, not a VM. So if the VM doesn’t have that advanced setting at all, then it’s not included in the list.  That’s why I got an incomplete and inaccurate list of advanced settings:  only VMs with the advanced setting were included.

Is there a better way to list the advanced settings of a VM in PowerCLI

So one of the first things I noticed in the output is that it didn’t include the name of the VM in the output.

The easy way to get incomplete information from Get-AdvancedSetting

Even though the machine name isn’t included by default in the output of Get-AdvancedSetting, it’s there in the object.

$SettingName = 'isolation.tools.diskshrink.disable'
Get-VM | Get-AdvancedSetting -Name $SettingName | Select Entity, Name, Value

This gives you the information you asked for – the machine name along with the setting – but it still doesn’t include any VMs that don’t have the setting.

The slightly more complicated way that shows every VM whether it has the advanced setting or not

$Setting = 'isolation.tools.diskshrink.disable'


Get-VM | Select-Object Name, @{Name="DiskShrinkDisabled"; Expression={
  ($_ | Get-AdvancedSetting -Name $Setting).Value 
 } #end Expression
 } #end Hashtable

Or you could take it that last extra step and report if the value is TRUE, FALSE or if it doesn’t exist:

$AdvancedSetting = "isolation.tools.diskshrink.disable"
Get-VM | `
 Select Name, @{Name="DiskShrink"; Expression={
   #Start "Expression
   if ( ($_ | Get-AdvancedSetting -Name $AdvancedSetting).Value -eq "true") {
     "Disabled"
   } else { 
     #Start "Is it enabled or blank?"
     if ($_ | Get-AdvancedSetting -Name $AdvancedSetting) {
       "Enabled" 
     } 
     else { 
       "Setting Doesn't Exist"
     }
     #End "Is it enabled or blank?"
   }
   #End "Expression"
  }
  #End "DiskShrink Hashtable"
 } | Format-Table -Autosize