VMware Cloud Community
SupportIG
Contributor
Contributor

Need help retrieving Advanced config information using Powershell.

I have spent a whole day trying to retrieve about advanced config options from each of my VM hosts using Powershell.

The probkem is that I have inherited an environment with a large number of hosts - that were not consistently configured.

I'd like to run a script to interrogate asdvanced settings for all of these servers and output this to a table for easy reading.

I have now managed to find 2 ways to change the data and 1 way to read the data for each host indivuidually . . but getting the values alone for each of the hosts and putting that in a table has got me stumped.

The bigger plan is to create a 'buil' script to configure our default settibngs on new hosts - I will continue to use this script as a weekly task to review my configs.

Editing these settings is easy:

e.g. Changing NFS.MaxVolumes

# Sets all Advanced VM settings for newly built VM Host

$hostname = "xxxx.yyy.zzz"

Connect-VIServer $hostname

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

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

$option = @()

$option = New-Object VMware.Vim.OptionValue

$option.key = "NFS.MaxVolumes"

$option.value = 32

$optMgr.UpdateOptions($option)

Or alternatively - simply use Set-VMHostAdvancedConfiguration

The real problem is trying to read the output into a table that looks something like:

HostName, TCPIPHeapMax, TCPIPHeapSize, HeartbeatFrequency, HeartbeatMaxFailures, MaxVolumes

abcdef, 120, 30, 12, 10,32

abcdef, 120, 30, 12, 10,16

abcdef, 120, 30, 8, 10,32

abcdef, 100, 30, 12, 10,32

I can get these values - but am unable to actually work out how to pull the numbers from the final values.

Here is my code:

Connect-VIServer abc

$VMhosts = Get-VMHost

$VMSummaries = @()

foreach ($VMHost in $VMhosts)

{

$VMSummary = "" | Select HostName, TCPIPHeapMax, TCPIPHeapSize, HeartbeatFrequency, HeartbeatMaxFailures, MaxVolumes

$VMSummary.HostName = $VMHost.Name

$VMSummary.TCPIPHeapMax = Get-VMHostAdvancedConfiguration -VMHost ($VMhost) -Name Net.TcpipHeapMax | Select-Object Values

$VMSummary.TCPIPHeapSize = Get-VMHostAdvancedConfiguration -VMHost ($VMhost) -Name Net.TcpipHeapSize | Select-Object Values

$VMSummary.HeartbeatFrequency = Get-VMHostAdvancedConfiguration -VMHost ($VMhost) -Name NFS.HeartbeatFrequency | Select-Object Values

$VMSummary.HeartbeatMaxFailures= Get-VMHostAdvancedConfiguration -VMHost ($VMhost) -Name NFS.HeartbeatMaxFailures | Select-Object Values

$VMSummary.MaxVolumes = Get-VMHostAdvancedConfiguration -VMHost ($VMhost) -Name NFS.MaxVolumes | Select-Object Values

+$VMSummaries = $VMSummary

}

$VMSummaries | Format-Table

Annoyingly, "Get-VMHostAdvancedConfiguration -VMHost ($VMhost) -Name Net.TcpipHeapMax | Select-Object Values" will actually show each individual output, or

"Get-VMHostAdvancedConfiguration -VMHost ($vmhosts) " will output the full list . . but I can not filter these settings by name to just the ones I need.

The final product needs to have one table for all ESX Hosts, along with the associated settings for TCPIPHeapMax, TCPIPHeapSize, HeartbeatFrequency, HeartbeatMaxFailures, MaxVolumes

Once I crack this . . I will try colour any anomalies . . but that is a new challenge! (I have only been using powershell for 2 days . . please be nice)

Thanks in advance for any help . .

0 Kudos
6 Replies
LucD
Leadership
Leadership

The Select-Object that you used returns a hash table, not just an integer value.

You could do something like this

$VMhosts = Get-VMHost
foreach ($VMHost in $VMhosts)
{
	$VMSummary = "" | Select HostName, TCPIPHeapMax, TCPIPHeapSize, HeartbeatFrequency, HeartbeatMaxFailures, MaxVolumes
	$VMSummary.HostName = $VMHost.Name
	$VMSummary.TCPIPHeapMax = (Get-VMHostAdvancedConfiguration -VMHost ($VMhost) -Name Net.TcpipHeapMax).Values
	$VMSummary.TCPIPHeapSize = (Get-VMHostAdvancedConfiguration -VMHost ($VMhost) -Name Net.TcpipHeapSize).Values
	$VMSummary.HeartbeatFrequency = (Get-VMHostAdvancedConfiguration -VMHost ($VMhost) -Name NFS.HeartbeatFrequency).Values
	$VMSummary.HeartbeatMaxFailures= (Get-VMHostAdvancedConfiguration -VMHost ($VMhost) -Name NFS.HeartbeatMaxFailures).Values
	$VMSummary.MaxVolumes = (Get-VMHostAdvancedConfiguration -VMHost ($VMhost) -Name NFS.MaxVolumes).Values
	$VMSummaries += $VMSummary
}
$VMSummaries | Format-Table

Note that this could still give a problem when there is more than 1 value in the Values property.


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

0 Kudos
SupportIG
Contributor
Contributor

Thanks LucD ,

Thankfully, none of the fields I am chasing will ever have multiple values in the HashTable, so this does the job almost perfectly . . .

Sample output as follows:

HostName TCPIPHeapMax TCPIPHeapSize HeartbeatFrequency HeartbeatMaxFailures MaxVolumes

----


-
-
-
-
-

esx002.abc.... + +esx001.abc... + +esx001.abc....

0 Kudos
aw443
Contributor
Contributor

Luc,

I've been meaning to use this cmdlet to document my advanced config parameters for all my hosts to track changes, etc. This looks very useful and would be great, but i can't seem to get this code to run. I receive the following error:

Method invocation failed because http://System.Management.Automation.PSObject doesn't contain a method named 'op_Addition'.
At c:\temp\get-advcfg.ps1:13 char:17
+ $VMSummaries += <<<< $VMSummary

I've also tried using the get-content cmdlet which has been helpful for many other scripts in the past. I enter the list of hosts in the specificied txt file being called in the code below. It outputs the data formatted correctly, but only for one host. (i added a date field)

get-content c:\temp\hostlist.txt | foreach { $VMhosts = Get-VMHost $_
foreach ($VMHost in $VMhosts)
{
$VMSummary = "" | Select Date, HostName, TCPIPHeapMax, TCPIPHeapSize, HeartbeatFrequency, HeartbeatMaxFailures, MaxVolumes
$VMSummary.Date = get-date -uformat "%Y%m%d"
$VMSummary.HostName = $VMHost.Name
$VMSummary.TCPIPHeapMax = (Get-VMHostAdvancedConfiguration -VMHost ($VMhost) -Name Net.TcpipHeapMax).Values
$VMSummary.TCPIPHeapSize = (Get-VMHostAdvancedConfiguration -VMHost ($VMhost) -Name Net.TcpipHeapSize).Values
$VMSummary.HeartbeatFrequency = (Get-VMHostAdvancedConfiguration -VMHost ($VMhost) -Name NFS.HeartbeatFrequency).Values
$VMSummary.HeartbeatMaxFailures= (Get-VMHostAdvancedConfiguration -VMHost ($VMhost) -Name NFS.HeartbeatMaxFailures).Values
$VMSummary.MaxVolumes = (Get-VMHostAdvancedConfiguration -VMHost ($VMhost) -Name NFS.MaxVolumes).Values
$VMSummaries = $VMSummary
}
}
$VMSummaries | Format-Table

Results look like the following:

Date HostName TCPIPHeapMax TCPIPHeapSize HeartbeatFrequen HeartbeatMaxFail MaxVolumes

cy ures

-


-


-


-


-


-


-


20091014 esx05

Any thoughts or suggestions?

0 Kudos
LucD
Leadership
Leadership

You probably forgot the line

$VMSummaries = @()

which was only mentioned in the first script in this thread.

That's where you tell PowerShell that the variable $VMSummaries will be an array.

That will allow you to add a row to the array with this line

$VMSummaries += $VMSummary


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

0 Kudos
aw443
Contributor
Contributor

Wow. You are fast - and of course, you're right. I overlooked that line. This worked beautifully.

I'm going to use this to get all adv cfg parameters outputted in this format and append it to a file weekly ( i will add a "date" column for historical viewing).

Quick question, will I have to continue specifying all the advanced parameters that I want (I want to record them all), just like TCPIPHeapMax, etc were specified? If this is the only way, I will go ahead and do that. But wanted to run it by you first in case there is an easier way to specify all parameters and also have it output in a clean format like this code does.

0 Kudos
LucD
Leadership
Leadership

I think you will have to retrieve them one-by-one, but I'm not 100% sure.

Will have to do a test.


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

0 Kudos