Friday, July 30, 2010

Powershell to display Storage Model for each VMWare VM

Script below permit to display which storage model is used for each VM of you Virtual Center
Download it


#
# Storage Model by VM
#
# by Franck RICHARD
# 2010 July
#

# Connect VC
$VC = "localhost"
Connect-VIServer -Server $VC | Out-Null

# Get all Datastores
$datastores = Get-Datastore
# Get All VMs
$ArrVM = Get-VM
foreach ($VM in $arrVM) {
# Get VMHost View
$VMHostView = Get-VMHost -VM $VM | Get-View

# Get all HardDisks
$HardDisks = $VM | Get-HardDisk
foreach ($HardDisk in $HardDisks) {
# Filename = "[VMFS-PROD] COMPUTER01/COMPUTER01.vmdk" for example
$DatastoreVM = $HardDisk.Filename.Split("[]")[1]
$DatastoreVMView = $datastores | where {$_.name -eq $DatastoreVM} | Get-View

# Diskname = "vmhba2:0:20" for example
$VMFSextents = $DatastoreVMView.info.vmfs.extent
foreach ($VMFSextent in $VMFSextents) {
$Diskname = $vmfsextent.Diskname
#Write-Host "Diskname:"$Diskname
}

$ScsiLuns = $VMHostView.Config.StorageDevice.ScsiLun
$bDiskFound = $False
foreach ($ScsiLun in $ScsiLuns) {
if ($ScsiLun.CanonicalName -eq $Diskname) {
#For Example
# CanonicalName = "vmhba2:0:0"
# Vendor = "EMC"
# Model = "SYMMETRIX"
$bDiskFound = $True
break
}
}

if ($bDiskFound) {
Write-Host "Name:" $VM.Name $HardDisk.Name $ScsiLun.CanonicalName "Vendor:"$ScsiLun.Vendor "Model:"$ScsiLun.Model
} else {
Write-Host "Name:" $VM.Name $diskname "not found"
}
# break # if all HardDisks are on the SAN
} # Foreach $HardDisk
} # Foreach $VM

No comments: