Hello,
I wish to create separate HTML reports for each cluster I have in my virtual center. I have created a script but it doesnt seem to be working. This script does create separate HTML outputs based on the clusters however all the files have the same data i.e. all the datastores which are available in the Vcenter. How do I separate them with respect to the cluster in which they are assigned instead?
===========================================================
# Functions for mathematical operations.
function usedspace{
param($datastore)
[math]::Round(($datastore.CapacityMB - $datastore.FreeSpaceMB)/1024,2)
}
function dscapacity{
param($datastore)
[math]::Round($datastore.CapacityMB/1024,2)
}
function freespace{
param($datastore)
[math]::Round($datastore.FreeSpaceMB/1024,2)
}
function percent{
param($datastore)
[math]::Round((($datastore.FreeSpaceMB/1024)/($datastore.CapacityMB/1024)*100)/1,2)
}
#Connect to Vcenter
connect-viserver -server <myservername>
# CSS stylesheet
$a = "<style>"
$a = $a + "BODY{background-color:Gainsboro;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:SkyBlue}"
$a = $a + "TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;background-color:PaleTurquoise}"
$a = $a + "*{font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;}"
$a = $a + "</style>"
# get a list of the clusters
$clusters = get-cluster
# Create HTML report for each cluster
foreach ($cluster in $clusters )
{
$datastores = Get-Datastore | where { $_.name -notcontains "local"} | sort Name
$Report = @()
ForEach ($datastore in $datastores){
$row = "" | select-object Datastore, Datacenter, CapacityGB, UsedGB, FreeSpaceGB, PercentFree
$row.Datastore = $datastore.Name
$row.Datacenter = $datastore.Datacenter
$row.CapacityGB = dscapacity $datastore
$row.UsedGB = usedspace $datastore
$row.FreeSpaceGB = freespace $datastore
$row.PercentFree = percent $datastore
$Report += $row
}
$Report |sort-object -Property PercentFree| ConvertTo-Html -head $a | Set-Content "D:\VMware\Scripts\Reports\Storage\$cluster.html"
}
===============================================================
To retrieve the datastores per cluster, you have to modify the line:
$datastores = Get-Datastore | where { $_.name -notcontains "local"} | sort Name
into:
$datastores = $cluster | Get-Datastore | where { $_.name -notcontains "local"} | sort Name
To retrieve the datastores per cluster, you have to modify the line:
$datastores = Get-Datastore | where { $_.name -notcontains "local"} | sort Name
into:
$datastores = $cluster | Get-Datastore | where { $_.name -notcontains "local"} | sort Name
Thanks a lot. Works great.
One more thing..
This line does not filter out my local ESXI datastores. any idea why?
$datastores = $cluster | Get-Datastore | where { $_.name -notcontains "local"}
-notcontains is for finding elements in arrays.
You can try:
$datastores = $cluster | Get-Datastore | where { $_.name -notlike "*local*"}