VMware Cloud Community
bubbzie
Contributor
Contributor

modifying host Advance option for multiple nodes

This is continuation from previous thread, but I got no answer, I figured maybe to try as separate thread would be eye catchy Smiley Happy

thread was answered by LucD:

$tgtkey = "NFS.MaxVolumes"

$tgtvalue = 12

$esx = Get-View -ViewType HostSystem -Filter @{"Name" = <ESX-host>}

$optMgr = Get-View -Id $esx.ConfigManager.AdvancedOption

So, I was trying to modify this to include multiple hosts (or specific datacenter etc.):

$tgtkey = "NFS.MaxVolumes"

$tgtvalue = 12

$myhosts = get-vmhost|select Name

$esx = Get-View -ViewType HostSystem -Filter @{"Name" = $myhosts}

$optMgr = Get-View -Id $esx.ConfigManager.AdvancedOption

rest of code...

however I get error:

Invalid object specified for parameter Filter - 'Hashtable{String, Object[]}'. Valid type is 'Hashtable{String, String}'.

At :line:6 char:21

+ $hostView = Get-View <<<< -ViewType HostSystem -Filter @{"Name" = $myHosts }

I also tried:

ForEach ($VMHosts in Get-VMHost){

$hostView = Get-View -ViewType HostSystem -Filter @{"Name" = $myHosts }

rest of code...

I get same error as above. So I guess what is it complaining 'Hashtable{String, String}', but I can't figure out how to provide array instead of string, if that's the complain...

0 Kudos
2 Replies
LucD
Leadership
Leadership

The -Filter parameter on Get-View should pass a hashtable with key-value pairs.

The key is property against which you want to test (the Name in this case) and the value you want to match.

Note that the value string is a regular expression!

To make it work with multiple hosts you could create a regular expression with the "|" operator between the possible values.

Something like this

$tgtkey = "NFS.MaxVolumes"
$tgtvalue = 12
$myhosts = get-vmhost|select Name
$myHostNames = ""
$myhosts | %{$myHostNames += ($_.Name + "|")}
$myHostNames = $myHostNames.TrimEnd("|")
$esx = Get-View -ViewType HostSystem -Filter @{"Name" = $myHostNames}

$esx | %{
   $optMgr = Get-View -Id $_.ConfigManager.AdvancedOption

   $optarr = @() 
   $option = New-Object VMware.Vim.OptionValue
   $option.key = $tgtkey
   $option.value = $tgtvalue
   $optarr += $option
   $optMgr.UpdateOptions($optarr)
}

Note that $esx will now be an array and contain multiple HostSystem objects.

That's why you the Foreach-Object loop.

Hope this helped.


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

0 Kudos
bubbzie
Contributor
Contributor

Great! Thank you LucD!

0 Kudos