Check host advanced settings using powercli


I wanted to check settings for NFS that i have in place for all hosts in specific cluster.
Here is what i came up with:

get-cluster 'myCluster' | get-vmhost | %{ $hostn=$_.Name; Get-VMHostAdvancedConfiguration -VMHost $_ | % { $_.getEnumerator()| ? {$_.Key -like "NFS*"}|select Name,Value,@{N='host';E={$hostn}} }  } | export-csv c:\nfssettings.csv
----Output before sending to export-csv
Name                            Value host
----                            ----- ----
NFS.WorldletAffinity            x     host1
NFS.VolumeRemountFrequency      y     host1
NFS.LockUpdateTimeout           z     host1
NFS.LogNfsStat3                 y     host2

In nfssettings.csv you will have nice table with nfs_setting_name , value, and host name from which it was taken.
What’s with the $_.GetEnumerator() ?, right, so when you will run

Get-VMHostAdvancedConfiguration -vmhost "your_host" | gm

You will notice that we are receiving hashtable. Since this is hashtable we can not fitler it with just simple where,select as this comes as a 1 BIG table. It looks like it consists of rows etc etc… so you would think that those are several objects, but at the end it is just like 1 big hashtable 😉 So we want to have ability to go through each element in this hashtable to search only for those with key similar to NFS*. Obviously if you want to search for other things like NFS, then put the proper name instead of NFS.

Get-VMHostAdvancedConfiguration -vmhost "your_host"
(Get-VMHostAdvancedConfiguration -vmhost "your_host").GetEnumerator()

Although they output is the same, when you are using GetEnumerator it is possible for you to do select with where-object.
Instead of receiving object type of hashtable, we are receiving now multiple System.Collections.DictionaryEntry which have Key and Value property. That’s why now we can use Where-Object to seek for your NFS settings.Since we are querying all host systems within cluster i want to have also a column with host name so that’s why i had to do $hostn=$_.Name; in the loop. To store the host name because this information would be lost in next pipeline.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s