I written this simple and small script, and use to pull datastore inventory data regularly to review the usage and other information, this script, helps me lot in many situation as an Inventory, Capacity Management or any other stuffs. It pulls below details,
Hostname
Datastore Name
Runtime ID
Connonical Device ID (Naa ID)
FreeSpace and Capacity in GB
VMFS File system version
Multipathing Policy for Hostname (Where Datastore is mounted)
How many datacenter this datastore belongs to
all the VMs running on the datastores
This is the data format it will pull.
I will be adding provisioned space to it soon.
Hostname
Datastore Name
Runtime ID
Connonical Device ID (Naa ID)
FreeSpace and Capacity in GB
VMFS File system version
Multipathing Policy for Hostname (Where Datastore is mounted)
How many datacenter this datastore belongs to
all the VMs running on the datastores
#####################################
## http://kunaludapi.blogspot.com
## Version: 2
## Date: 27 August 2014
## Script tested on below platform
## 1) Powershell v3
## 2) Powercli v5.5
## 3) Vsphere 5.1
####################################
Add-PSSnapin vmware.vimautomation.core
Connect-Viserver #vcenterserver
function Get-DatastoreInventory {
$HostDatastoreInfo = Get-VMHost | Get-ScsiLun -LunType disk
$DatastoreInfo = Get-Datastore
foreach ($Hostdatastore in $HostDatastoreInfo) {
$Datastore = $DatastoreInfo | Where-Object {$_.extensiondata.info.vmfs.extent.Diskname -match $Hostdatastore.CanonicalName}
if ($Datastore.ExtensionData.vm) {
$VMsOnDatastore = $(Get-view $Datastore.ExtensionData.vm).name -join ","
}
else {$VMsOnDatastore = "No VMs"}
#Work on not assigned Luns error at silentlyContinue
$DatastoreName = $Datastore.Name -join ","
$DatastoreFreeSpace = $Datastore.FreeSpaceGB -join ","
$DatastoreCapacityGB = $Datastore.CapacityGB -join ","
$DatastoreDatacenter = $Datastore.Datacenter -join ","
$Obj = New-Object PSObject
$Obj | Add-Member -Name VMhost -MemberType NoteProperty -Value $hostdatastore.VMHost
$Obj | Add-Member -Name DatastoreName -MemberType NoteProperty -Value $DatastoreName
$Obj | Add-Member -Name FreeSpaceGB -MemberType NoteProperty -Value $DatastoreFreeSpace
$Obj | Add-Member -Name CapacityGB -MemberType NoteProperty -Value $DatastoreCapacityGB
$Obj | Add-Member -Name FileSystemVersion -MemberType NoteProperty -Value $Datastore[0].FileSystemVersion
$Obj | Add-Member -Name RuntimeName -MemberType NoteProperty -Value $hostdatastore.RuntimeName
$Obj | Add-Member -Name CanonicalName -MemberType NoteProperty -Value $hostdatastore.CanonicalName
$Obj | Add-Member -Name MultipathPolicy -MemberType NoteProperty -Value $hostdatastore.MultipathPolicy
$Obj | Add-Member -Name Vendor -MemberType NoteProperty -Value $hostdatastore.Vendor
$Obj | Add-Member -Name DatastoreDatacenter -MemberType NoteProperty -Value $DatastoreDatacenter
$Obj | Add-Member -Name VMsOnDataStore -MemberType NoteProperty -Value $VMsOnDatastore
$Obj
}
}
Get-DatastoreInventory
This is the data format it will pull.
I will be adding provisioned space to it soon.
No comments:
Post a Comment