none
[Powershell] - Cluster volume information RRS feed

  • Question

  • Hi all and good morning.

    I found a script in powershell that says the information about Volume on the cluster and sends an email 

    I'm trying to create a new label on the script but i don't know how to do it.

    Please, if someone has some knowledge how to do that i'll be glad.

    The script is:

    #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 = "x.y.z.w" #Enter FQDN of SMTP server
    $SmtpFrom = "CSV Status <CSVFreeSpace@celtrino.com>" #Enter sender email address
    $SmtpTo = "julio.melo@some.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)

    The result of the script it's gonna be like that

    The following shows the amount of free space available on the cluster shared volumes on DRSRVVSA.

    Name          : Cluster Disk 1

    Path          : C:\ClusterStorage\Volume1

    Size(GB)      : 250.00

    FreeSpace(GB) : 16.37

    UsedSpace(GB) : 233.63

    PercentFree   : 6.55

    Name          : Cluster Disk 4

    Path          : C:\ClusterStorage\Volume2

    Size(GB)      : 499.88

    FreeSpace(GB) : 100.78

    UsedSpace(GB) : 399.11

    PercentFree   : 20.16

    Name          : Cluster Disk 6

    Path          : C:\ClusterStorage\Volume3

    Size(GB)      : 500.01

    FreeSpace(GB) : 87.94

    UsedSpace(GB) : 412.06

    PercentFree   : 17.59

    --------------------------------------------------------------------------------

    I'd like to add a new label under the "PercentFree" called "Status" and it'll be a condition. If PercentFree is less than 10.00 "Status : Warning", if "Status is greater than 10.0 "Status : OK".


    Thanks a million you all and have a great day.



    Na vida há dois caminhos mais só um que vai na direção certa


    • Edited by Julio Melo Wednesday, April 18, 2018 8:09 AM
    Wednesday, April 18, 2018 8:07 AM

Answers