Automation

 View Only
  • 1.  get-advancedsetting only showing a limited set of results

    Posted Mar 20, 2015 03:44 PM

    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



  • 2.  RE: get-advancedsetting only showing a limited set of results

    Posted Mar 20, 2015 06:12 PM

    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*"}



  • 3.  RE: get-advancedsetting only showing a limited set of results

    Posted Mar 20, 2015 06:23 PM

    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



  • 4.  RE: get-advancedsetting only showing a limited set of results
    Best Answer

    Posted Mar 20, 2015 08:06 PM

    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}}



  • 5.  RE: get-advancedsetting only showing a limited set of results

    Posted Mar 20, 2015 10:27 PM

    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



  • 6.  RE: get-advancedsetting only showing a limited set of results

    Posted Mar 20, 2015 10:57 PM

    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.



  • 7.  RE: get-advancedsetting only showing a limited set of results

    Posted Feb 01, 2022 01:23 AM

    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  



  • 8.  RE: get-advancedsetting only showing a limited set of results

    Posted Feb 01, 2022 07:10 AM

    Yes