Friday, March 18, 2011

Get/Set custom field in Vmware - Is your VM replicated example ?

For billing and production information, I need to know if SAN is replicated or not.
I use a powershell script to indicate me if ESX host is replicate or not using Virtual Center Custom Field.

First, I must set a value to all ESX for indicate me if this ESX have replicated LUN

To set "Replication" in all your hosts

$VMHosts = Get-VMHost | Sort Name
$CustomField = "Replication"
Foreach ($VMHost in $VMHosts){
Write-Host ($VMHost).Name
Set-CustomField -Entity $VMHost -name $CustomField -Value "Yes"
}



Now, for some ESX with no replication set Custom Field Replication manually to No

To do that, select your host then in summary tab in annotations click on edit


















Then in "Edit Annotations" window change value of Replication field











Now, if you need to know if your VM is replicated use this powershell code

$ArrVM = Get-VM
foreach ($VM in $arrVM) {
$VMHost = Get-VMHost -VM $VM
$Replication = $True
If ($VMHost.CustomFields["Replication"].ToUpper() -eq "NO") {
$Replication = $False
}
Write-Host $VM.Name "replication:" $Replication
}

No comments: