Powershell Script to find Hyper-V Cluster-wide and Host level storage space available

Murty M
Murty M used Ask the Experts™
on
Looking for PS Script;
Powershell Script to find Hyper-V Cluster-wide and Host level storage space available and export the Data to Excel Sheet with 2 Columns and 2 Rows:
Columns Required: 1) Total Space available in Cluster 2) Total space available in Host​
Rows Required: 1) Cluster Name 2) Host Name​
Server Edition: Microsoft Windows Server 2016 Datacenter Edition - Hyper-V
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
AlexSenior Infrastructure Analyst

Commented:
https://gallery.technet.microsoft.com/Get-HyperVInventory-Create-2c368c50

That'll pull pretty much everything you'll want and more, worth a look at unless you can get something more bespoke.

Author

Commented:
Checked the Script, below two Columns needs to be added in output
Columns Required: 1) Total Space available in Cluster 2) Total space available in Host​
Could you please provide the customized Script?
We need the output as in table once we supply host/cluster names in txt file.
Technical Architect - HA/Compute/Storage
Commented:
This script is set up to e-mail the results:
# From: http://www.bizzonitservices.com/2015/10/12/powershell-automation-get-cluster-shared-volumes-disk-space-report/
#
# Get Cluster Shared Volumes Disk space report
#
$threshhold = 10
$date = (Get-Date).ToString()
$LogFile = “C:\ReportLowDiskSpace\Logs.txt” # Change to any desired path
$Hostname = “” # Enter the hostname for one of the node in cluster
Add-Content $LogFile “`n”
Add-Content $LogFile $date
Add-Content $LogFile “`n====================================”
$smtpServer = “”
$smtpFrom = “email@yourdomain.com”
$smtpTo = “email@yourdomain.com”
$smtpcc = “”
$DiskInfo = Get-ClusterSharedVolume -Cluster $Hostname |
ForEach-Object {
[PSCustomObject]@{VolumeName = $_.Name;
OwnerNode = $_.OwnerNode;
Size = [math]::round(($_.SharedVolumeInfo.Partition.Size)/ 1GB);
UsedSpace = [math]::round(($_.SharedVolumeInfo.Partition.Usedspace)/ 1GB);
#UsedSpace = $_.SharedVolumeInfo.Partition.Usedspace
FreeSpace = [math]::round(($_.SharedVolumeInfo.Partition.FreeSpace)/ 1GB) ;
FreePercent =$_.SharedVolumeInfo.Partition.PercentFree
}}

Add-Content $LogFile “`n DiskInfo = $DiskInfo”
$lowOnDiskSpace = $DiskInfo | ? {$_.Freepercent -lt $threshhold} | ft
#
# Send Email Message
#
if($lowOnDiskSpace -ne $Null)
{
$messageSubject = “Alert: Low Disk Space on $Hostname”
$messageBody = $lowOnDiskSpace | out-string
Try
{
send-mailmessage -smtpserver $smtpServer -to $smtpTo -from $smtpFrom -subject $messageSubject -Body $messageBody
Add-Content $LogFile “`n Alert Sent: Low Disk Space on $hostname”
}
Catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Add-Content $LogFile “`n”
Add-Content $LogFile $ErrorMessage
Add-Content $LogFile “`n”
Add-Content $LogFile $FailedItem
}
}
Else
{
$messageSubject = “Information: Disk Space on $hostname”
$messageBody = $DiskInfo |ft | out-string
Try
{
send-mailmessage -smtpserver $smtpServer -to $smtpTo -from $smtpFrom -subject $messageSubject -Body $messageBody
Add-Content $LogFile “`n Information Sent: Disk Space on $hostname”
}
Catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Add-Content $LogFile “`n”
Add-Content $LogFile $ErrorMessage
Add-Content $LogFile “`n”
Add-Content $LogFile $FailedItem
}
}

Open in new window

Philip ElderTechnical Architect - HA/Compute/Storage
Commented:
This one may be a little more focused on the Q:
# From: https://blogs.msdn.microsoft.com/clustering/2010/06/18/powershell-for-failover-clustering-csv-free-disk-space-and-other-info/
$objs = @()

$csvs = Get-ClusterSharedVolume
foreach ( $csv in $csvs )
{
   $csvinfos = $csv | select -Property Name -ExpandProperty SharedVolumeInfo
   foreach ( $csvinfo in $csvinfos )
   {
      $obj = New-Object PSObject -Property @{
         Name        = $csv.Name
         Path        = $csvinfo.FriendlyVolumeName
         Size        = $csvinfo.Partition.Size
         FreeSpace   = $csvinfo.Partition.FreeSpace
         UsedSpace   = $csvinfo.Partition.UsedSpace
         PercentFree = $csvinfo.Partition.PercentFree
      }
      $objs += $obj
   }
}

$objs | ft -auto Name,Path,@{ Label = "Size(GB)" ; Expression = { "{0:N2}" -f ($_.Size/1024/1024/1024) } },@{ Label = "FreeSpace(GB)" ; Expression = { "{0:N2}" -f ($_.FreeSpace/1024/1024/1024) } },@{ Label = "UsedSpace(GB)" ; Expression = { "{0:N2}" -f ($_.UsedSpace/1024/1024/1024) } },@{ Label = "PercentFree" ; Expression = { "{0:N2}" -f ($_.PercentFree) } }

# Export to CSV
$objs | ft -auto Name,Path,@{ Label = "Size(GB)" ; Expression = { "{0:N2}" -f ($_.Size/1024/1024/1024) } },@{ Label = "FreeSpace(GB)" ; Expression = { "{0:N2}" -f ($_.FreeSpace/1024/1024/1024) } },@{ Label = "UsedSpace(GB)" ; Expression = { "{0:N2}" -f ($_.UsedSpace/1024/1024/1024) } },@{ Label = "PercentFree" ; Expression = { "{0:N2}" -f ($_.PercentFree) } } | Export-Csv -Path C:\Temp\ClusterCSVStatus.CSV 

Open in new window

Author

Commented:
Thank you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial