Failover Clustering, Hyper-V, Powershell

Monitoring Cluster Shared Volume – PowerShell

I have found this but haven't tested yet. I will tweak and use it soon.
#Cluster Shared Volume Free Disk Space
#Emails results of CSV free space on CLUSTER1
#Created 03-08-2011
#-------------------------------------------------------------------------------------------------

#Import Failover Cluster PowerShell Module--------------------------------------------------------
Import-Module FailoverClusters
#-------------------------------------------------------------------------------------------------

#Begin customization-------------------------
$SmtpServer = "mail.company.com" #Enter FQDN of SMTP server
$SmtpFrom = "CSV Status <CSVFreeSpace@company.com>" #Enter sender email address
$SmtpTo = "you@company.com" #Enter one or more recipient addresses in an array ("abc@company.com","def@company.com")
$SmtpSubject = "CLUSTER1 CSV Free Disk Space Report" #Enter subject of message
#End customization---------------------------

#Get Cluster Shared Volume details and put into array. Convert results from bytes into gigabytes.
$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
   }
}

#Original code
#$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) } }
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#Give a brief description of the output
$output = "The following shows the amount of free space available on the cluster shared volumes on DRSRVVSA."
#Modified code that puts results into a variable and formats results into list format
$output += $objs | fl 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) } } | out-string
#------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#Email results
$SmtpClient = New-Object System.Net.Mail.SmtpClient
$MailMessage = New-Object System.Net.Mail.MailMessage
$SmtpClient.Host = $SmtpServer
$MailMessage.From = $SmtpFrom
Foreach ($address in $smtpTo)
	{$MailMessage.To.Add($address)}
$MailMessage.Subject = $SmtpSubject
#$MailMessage.IsBodyHTML = $true
$MailMessage.Body = $output
$SmtpClient.Send($MailMessage)

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s