VMware Cloud Community
tekhie
Contributor
Contributor
Jump to solution

Datastore information by cluster

Hi - i was wondering if anyone has a script that can detail the following information .in a table..

Cluster Name -> Datastore Name -> Total size -> Space free -> % of space used

I have 2 clusters where the Datastore names are the same in each cluster. I would like a way of being able to see which Datastores have 15% or less free space and which cluster the datastore belongs to.

If anyone can help with this that would be great

regards

chris

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

We can't use the WHer-Object cmdlet here since we're not testing in a pipe.

But a straightforward if statement with the StartsWith method should do the trick.

Something like this:

$report = @()

Get-Cluster $clusterName | Get-View | % {
	foreach($dsMoRef in $cluster.Datastore){
		$ds = Get-View -Id $dsMoRef
		if(-not $ds.Info.Name.StartsWith("LOCAL")){
			$row = "" | Select Cluster, Datastore, Size, Free, UsedPercentage
			$row.Cluster = $cluster.Name
			$row.Datastore = $ds.Info.Name
			$row.Size = $ds.Info.Vmfs.Capacity
			$row.Free = $ds.Info.FreeSpace
			$row.UsedPercentage = "{0:N2}" -f (($row.Size - $row.Free)/$row.Size * 100)
			$report += $row
		}
	}
}
$report


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

View solution in original post

0 Kudos
8 Replies
LucD
Leadership
Leadership
Jump to solution

You could do that this way.

$report = @()

Get-Cluster $clusterName | Get-View | %{
  foreach($dsMoRef in $cluster.Datastore){
	$ds = Get-View -Id $dsMoRef
	$row = "" | Select Cluster, Datastore, Size, Free, UsedPercentage
	$row.Cluster = $cluster.Name
	$row.Datastore = $ds.Info.Name
	$row.Size = $ds.Info.Vmfs.Capacity
	$row.Free = $ds.Info.FreeSpace
	$row.UsedPercentage = "{0:N2}" -f (($row.Size - $row.Free)/$row.Size * 100)
  	$report += $row
  }
}
$report


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

banerian
VMware Employee
VMware Employee
Jump to solution

What about differentiating between local VMFS file systems and SAN-based VMFS file systems? I am only interested in the SAN-side VMFSs. I tried using "MultipleHostAccess" but that fails for VMFSs that are SAN-based but have only one host connected to them.

Is there a go-to, for-sure, works-no-matter-what (local boot, versus SAN boot, versus whatever is going on at the PCI level, ...) way to differentiate between the two?

Thanks,

John

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Could the Vendor property that is returned by the Get-ScsiLun cmdlet be a good candidate for a filter ?

I have for example a number of OpenFiler iSCSI LUNs in my test environment.

To get at these I do

Get-ScsiLun -VmHost (Get-VMHost esx1.test.local) | where {$_.Vendor -eq "OPNFILER"}

This returns an array with ScsiLunImpl objects and one of the properties is the CanonicalName.

You could use this canonicalname to test against the diskname of the SCSI extent of the VMFS volume.

You end up with something like this

$report = @()
$OpenFilerLuns = Get-ScsiLun -VmHost (Get-VMHost esx1.test.local) | where {$_.Vendor -eq "OPNFILER"} | %{$_.CanonicalName}

Get-Cluster $clusterName | Get-View | % {
	$esx = Get-View -Id $_.Host[0]
	foreach($dsMoRef in $cluster.Datastore){
		$ds = Get-View -Id $dsMoRef
		if($ds.Summary.Type -eq "VMFS" -and $OpenFilerLuns -contains $ds.Info.Vmfs.Extent[0].DiskName){
			$row = "" | Select Cluster, Datastore, Size, Free, UsedPercentage
			$row.Cluster = $cluster.Name
			$row.Datastore = $ds.Info.Name
			$row.Size = $ds.Info.Vmfs.Capacity
			$row.Free = $ds.Info.FreeSpace
			$row.UsedPercentage = "{0:N2}" -f (($row.Size - $row.Free)/$row.Size * 100)
			$report += $row
		}
	}
}
$report


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

0 Kudos
banerian
VMware Employee
VMware Employee
Jump to solution

Well, I'm trying to get the Capacity and Free info, in aggregate, by Datacenter, just for SAN storage.

Get-scsilun does seem to work if I call it like this:

Get-Datacenter -server $VCS -name $dcName | get-vmhost | Get-ScsiLun

And the output looks promising - for example maybe I could use LunType

But, looking at the output, this will only pull Capacity and not Free space, like the get-datastore command does, so, even if the above issues iron themselves out I'm still stuck.

.... who would have thought this would be tricky?

0 Kudos
tekhie
Contributor
Contributor
Jump to solution

Hi LucD - thanks for the advice - it was very helpful I have tweaked the script a little so that it gives me the following headers ...

Cluster - Datastore - Size - Free - UsedPercentage

One further question i have is how i could go about changing the script so that it does not show any Datastores beginning LOCAL_xxx (these are the local vmfs partitions on each ESX Host which i do not want in the report) ? I have tried many ways but cant seem to get it to work ;-(

I have the following line from another piece of code ..

$lun = Get-Datastore | where {-not $_.Name.Contains("LOCAL")}

But i cannot work out how to integrate it into the code at the top of the page

Hope you can help so that all the info is in the one table

Tks in advance

Chris

0 Kudos
LucD
Leadership
Leadership
Jump to solution

We can't use the WHer-Object cmdlet here since we're not testing in a pipe.

But a straightforward if statement with the StartsWith method should do the trick.

Something like this:

$report = @()

Get-Cluster $clusterName | Get-View | % {
	foreach($dsMoRef in $cluster.Datastore){
		$ds = Get-View -Id $dsMoRef
		if(-not $ds.Info.Name.StartsWith("LOCAL")){
			$row = "" | Select Cluster, Datastore, Size, Free, UsedPercentage
			$row.Cluster = $cluster.Name
			$row.Datastore = $ds.Info.Name
			$row.Size = $ds.Info.Vmfs.Capacity
			$row.Free = $ds.Info.FreeSpace
			$row.UsedPercentage = "{0:N2}" -f (($row.Size - $row.Free)/$row.Size * 100)
			$report += $row
		}
	}
}
$report


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

0 Kudos
dj327731
Contributor
Contributor
Jump to solution

thanks for all the input. Finally go it working.  Anyone know of a good site to view sample scripts.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Just Google PowerCLI and you should find many blogs that have PowerCLI scripts.

And of course this community.


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

0 Kudos