VMware Cloud Community
gboskin
Enthusiast
Enthusiast
Jump to solution

Cluster settings

We have a situation where vmkping has suddenly stopped working in a cluster between different hosts. two other clusters in the same datacenter and enclosure works fine.

I need a script to get all the setting DRS,HA setting of all the three clusters to compare and also VMkernel IP and settings

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I looked at the problem and decided it was too much work to build all the logic into a script.

So I decided to tackle the problem from another angle.

Export all the settings to an external file and use an external tool to compare the files coming from the different clusters and ESX hosts.

Note that you could also use the Compare-Object cmdlet to compare the external files.

The Get-Properties function in following script was inspired by a script called List ALL available properties in the VI Toolkit from Hugo Peeters. I pimped his script and added the functionality to also show the value and type of each property.

The main script gets

1) all the cluster settings from the ClusterConfigInfoEx object

2) all the network settings, included the VmKernel portgroup, from the HostNetworkInfo object

The script will produce several CSV files:

1) -network.CSV for each ESX host in each cluster containing the ESX host network settings

function Get-Properties{
	param($BaseName)

	$row = New-Object System.Object
	$row | Add-Member -memberType NoteProperty -name Name -value ""
	$row | Add-Member -memberType NoteProperty -name Value -value ""
	$row | Add-Member -memberType NoteProperty -name Type -value ""
	$row.Name = $BaseName

	$result = Invoke-Expression $BaseName
	if($result -ne $null){
		$type = $result.GetType()
		if($type.IsArray){
			for($i = 0; $i -lt $result.Count; $i++){
				$element = $BaseName + ""
				Get-Properties $element
			}
		}
		elseif($type.IsPrimitive -or $type.Name -eq "String"){
			$row.Value = $result
			$row.Type = $type.Name
			if(-not ($row.Name -match "DynamicProperty$|DynamicType$")){
				$row
			}
		}
		else{
			$props = $result | gm -memberType Property,NoteProperty
			foreach($prop in $props){
				$NewName = $BaseName + "." + $prop.Name
				Get-Properties $NewName
			}
		}
	}
	else{
		if(-not ($row.Name -match "DynamicProperty$|DynamicType$")){
			$row
		}
	}
}

$cluster = Get-Cluster | Get-View | % {
	$clusterName = $_.Name
	$confEx = $_.ConfigurationEx
	$VariableName = '$confEx'

	$report = Get-Properties $VariableName
	$report | Sort-Object -property Name | Export-Csv ("C:\" + $clusterName + ".csv") -noTypeInformation

	$_.Host | % {
		$esxhost = Get-View -Id $_
		$network = $esxhost.Config.Network
		$VariableName = '$network'

		$report = Get-Properties $VariableName
		$report | Sort-Object -property Name | Export-Csv ("C:\" + $clusterName + "-" + $esxhost.Name + "-network.csv") -noTypeInformation
	}

}

Come to think of it, this script could also be used to save your important VI/vSphere settings to external files.

With some extra logic it could function as a kind of "host profile". Now where have I heard that name before.

Perhaps something for our VMworld session Smiley Wink


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

I looked at the problem and decided it was too much work to build all the logic into a script.

So I decided to tackle the problem from another angle.

Export all the settings to an external file and use an external tool to compare the files coming from the different clusters and ESX hosts.

Note that you could also use the Compare-Object cmdlet to compare the external files.

The Get-Properties function in following script was inspired by a script called List ALL available properties in the VI Toolkit from Hugo Peeters. I pimped his script and added the functionality to also show the value and type of each property.

The main script gets

1) all the cluster settings from the ClusterConfigInfoEx object

2) all the network settings, included the VmKernel portgroup, from the HostNetworkInfo object

The script will produce several CSV files:

1) -network.CSV for each ESX host in each cluster containing the ESX host network settings

function Get-Properties{
	param($BaseName)

	$row = New-Object System.Object
	$row | Add-Member -memberType NoteProperty -name Name -value ""
	$row | Add-Member -memberType NoteProperty -name Value -value ""
	$row | Add-Member -memberType NoteProperty -name Type -value ""
	$row.Name = $BaseName

	$result = Invoke-Expression $BaseName
	if($result -ne $null){
		$type = $result.GetType()
		if($type.IsArray){
			for($i = 0; $i -lt $result.Count; $i++){
				$element = $BaseName + ""
				Get-Properties $element
			}
		}
		elseif($type.IsPrimitive -or $type.Name -eq "String"){
			$row.Value = $result
			$row.Type = $type.Name
			if(-not ($row.Name -match "DynamicProperty$|DynamicType$")){
				$row
			}
		}
		else{
			$props = $result | gm -memberType Property,NoteProperty
			foreach($prop in $props){
				$NewName = $BaseName + "." + $prop.Name
				Get-Properties $NewName
			}
		}
	}
	else{
		if(-not ($row.Name -match "DynamicProperty$|DynamicType$")){
			$row
		}
	}
}

$cluster = Get-Cluster | Get-View | % {
	$clusterName = $_.Name
	$confEx = $_.ConfigurationEx
	$VariableName = '$confEx'

	$report = Get-Properties $VariableName
	$report | Sort-Object -property Name | Export-Csv ("C:\" + $clusterName + ".csv") -noTypeInformation

	$_.Host | % {
		$esxhost = Get-View -Id $_
		$network = $esxhost.Config.Network
		$VariableName = '$network'

		$report = Get-Properties $VariableName
		$report | Sort-Object -property Name | Export-Csv ("C:\" + $clusterName + "-" + $esxhost.Name + "-network.csv") -noTypeInformation
	}

}

Come to think of it, this script could also be used to save your important VI/vSphere settings to external files.

With some extra logic it could function as a kind of "host profile". Now where have I heard that name before.

Perhaps something for our VMworld session Smiley Wink


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

0 Kudos
gboskin
Enthusiast
Enthusiast
Jump to solution

I think we all need to download and install LuCD VMware tools kit:D

0 Kudos
gboskin
Enthusiast
Enthusiast
Jump to solution

Thats cool LuCD bouncing the switch fixed the problem. However was wondering I have 3 clusters and each have various servers... what of if i wish to writie a script thats checks that all host can vmkping each other in a particular cluster an return results to an HTML file like host A ok can vmking other hosts . or HOSTS A cannot ping ...

so i can get the guys to run it as a kind or early moring check

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can run the vmkping via something like plink.exe from the Putty package.

With a script similar to this one

$User = <ESX-account>
$Pswd = <ESX-password>
$fromESX = <ESX-hostname-from>
$toESX = <ESX-hostname-to>

$mask = [regex]'(\d+).packets.transmitted,.(\d+).packets.received'

$plink = "<path-to-the-Putty-directory>\plink.exe"
$plinkoptions = " -v -batch -pw $Pswd"
$cmd1 = '/usr/sbin/vmkping -c 10 ' + $toESX

$remoteCommand = '"' + $cmd1 + '"'
$command = $plink + " " + $plinkoptions + " " + $User + "@" + $fromESX + " " + $remoteCommand

$msg = Invoke-Expression -command $command

$result = $mask.Matches($msg)
$transmitted = $result[0].Groups[1].Value
$received = $result[0].Groups[2].Value

Write-Host "From" $fromESX "to" $toESX
if($received -eq $transmitted){
	Write-Host "vmkping: 100% success"
}
else{
	Write-Host "vmkping: packets dropped"
}

You could put this functionality in a function and then run through all your clusters and for each cluster vmkping all ESX hosts in that cluster against each other.

Btw I found an issue with the previous script when it encountered a DateTime property.

An updated version is attached.


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

0 Kudos