VMware Cloud Community
lloydmills
Contributor
Contributor
Jump to solution

get-advancedsetting only showing a limited set of results

Hello All,

I am very new to using PowerCLI, so please be patient with me.

I am trying to determine which of our VM's have the advanced setting "device.hotplug" set to "true".

I think i have got the script to do it, the only issue is, it doesn't output the expected results.

When running a command that does not filter the results, it will only return results for 40 VM's, when i'm expecting just over 200.

This is the command i expect to return the value for every VM in a cluster:

Get-Cluster -name "cluster" | Get-vm | Get-AdvancedSetting -name devices.hotplug | Format-Table -Property Entity,Name,Value -AutoSize

I get a full list of VM's when i run:

Get-Cluster -name "cluster" | Get-vm

This should be all you need to see my issue, however, for good measure and any feedback, here is the small script i'm working on to only output VM's with the "device-hotplug" setting enabled. Any feedbacks or comments welcome.

$hosts = get-cluster -name "cluster" | get-vm |

    Where-Object {$_.name -notlike "exclude"

    }

$results = foreach ($vihost in $hosts) {

    get-vm -name $vihost | get-advancedsetting -name devices.hotplug |

    Where-Object {$_.Value -notlike "false"}

    }

$results | format-table -Property Entity,Name,Value -AutoSize

Cheers

Lloyd

Tags (1)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Are you sure every VM has that advanced setting set ?

Try like this, it should return all VMs, also the ones that do not have the setting

Get-Cluster -name 'cluster' | Get-VM |

Select Name,@{N='device.hotplug';E={$_ | Get-AdvancedSetting -name devices.hotplug | Select -ExpandProperty Value}}


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

View solution in original post

Reply
0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

Are you sure that Where-clause is correct ?

Where do you have 'exclude" in the VMname, at the beginning, at the end ...?

Try adding some meta-characters, like for example

Where-Object {$_.name -notlike "*exclude*"}


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

Reply
0 Kudos
lloydmills
Contributor
Contributor
Jump to solution

Hi LucD - i removed the actual value from the where-clause - it does have "*value" to exlcude certain VM's which end the same.

My main issue is around the lack of results when running the following:

Get-Cluster -name "cluster" | Get-vm | Get-AdvancedSetting -name devices.hotplug | Format-Table -Property Entity,Name,Value -AutoSize

It only outputs around 1/5th of the VM's in the cluster

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are you sure every VM has that advanced setting set ?

Try like this, it should return all VMs, also the ones that do not have the setting

Get-Cluster -name 'cluster' | Get-VM |

Select Name,@{N='device.hotplug';E={$_ | Get-AdvancedSetting -name devices.hotplug | Select -ExpandProperty Value}}


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

Reply
0 Kudos
lloydmills
Contributor
Contributor
Jump to solution

you were correct - not all VM's had the setting, these were the ones that weren't being included in the results.

Thanks for that. Now i've just got to figure out how your command works

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

It's quite straightforward.

We get all the VMs and for each VM we return the name and the advanced setting through a calculated property.

If the advanced setting is not there, that calculated property will return $null.


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

Reply
0 Kudos
sjoshi25
Contributor
Contributor
Jump to solution

Follow up question on similar script for advanced settings:

I am using a script to export to CSV certain advanced settings for all VMs in a vCenter. Most of the results are blank and I did a quick spot check on the vSphere client that for one of the settings which was not present. Does that mean the advanced setting is not present if the results are blank in the export and in PowerCLI  

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes


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

Reply
0 Kudos