Microsoft Virtualization Discussions

Get-ncvol command to generate a list of offline volumes from multiple clusters and send a report.

RayR
3,464 Views

Get-ncvol command to generate a list of offline volumes from multiple clusters and send a report.  I'm new to using powershell and would like to get some help on this. 

2 REPLIES 2

donny_lang
3,367 Views

Do you have any code written yet that we could take a look at it and give feedback on? Some ideas to get you started:

 

1. Look at the "Add-NcCredential" cmdlet in the PowerShell Toolkit to cache credentials to clusters to make connecting to them easier when running scripts/functions (check out the Get-Help cmdlet to get more information, syntax, examples, etc. for cmdlets if you are not familiar with it already). 

2. You will need to use foreach loops to loop through a collection of your cluster hostnames. 

3. If you're not familiar with it already, look at the Where-Object cmdlet, which allows you to select objects from command output based on their properties (like the state of a volume, for example). Pipes are your friend! 

4. What format are you expecting this report to be in? If email, you can use the "Send-MailMessage" cmdlet to format and send the relevant output to you. 

 

Hope this helps - feel free to hit me up with any code that you're struggling with or any follow-up questions and I'll lend a hand. 

 

Donny

RayR
3,362 Views

So I found this script for generating reports for snapshots. I figured I can use it as a template and modify the commands for generating reports for offline volumes from multiple clusters. I'll review the links you sent me foreach loops and where-object and paste the command here again. 

 

@"
===============================================================================
Title: Netapp Offline Volume notifications.ps1
Description: List offline volumes on the Netapp clusters.
Requirements: Windows Powershell and the Netapp Powershell Toolkit
Author: Ed Grigson
===============================================================================
"@

Import-module DataOnTap

#Age of snapshot (in days) before it's included in the report
#$WarningDays = 7
#List the filers you want to scan
$NetappList=("clusters")
#List of email recipients
$emailNotifications=("emailaddress")
#SMTP server - replace with your SMTP relay below
$emailServer="x.x.x.x"
$Now=Get-Date

#Generate HTML output that uses CSS for style formatting.
$emailContent = "<html><head><title></title><style type=""text/css"">.Error {color:#FF0000;font-weight: bold;}.Title {background: #0077D4;color: #FFFFFF;text-align:center;font-weight: bold;}.Normal {}</style></head><body>"
$emailContent += "<p>Please scan the list of offline volumes and destroy it if not needed"
#$emailContent += "<p>Only snapshots over $WarningDays days old are shown."

foreach ($netapp in $NetappList) {
$emailContent += "<h2>$Netapp</h2>"
$emailContent += "<table><tr class='Title'><td colspan='4'>Netapp Offline Volume Report</td></tr><tr class='Title'><td>List of Volumes"
$Report = @()
Connect-NcController $netapp | select Name,Address
Get-NcVol -Query @{State="*offline*"} | Format-Table Name,State,Aggregate,Vserver
$ParentName=$_.Name
$Snap = get-ncvol $ParentName | add-member -membertype noteproperty -name ParentName -value $ParentName -passthru | select ParentName,Name
$Report += $Snap
}
Foreach ($snapshot in ($Report | Sort-Object -property AccessTime)){
#see if the snapshot is older than the value specified in $WarningDays and if so include in report
if ($snapshot.AccessTime -le $Now.AddDays(-$WarningDays)) {
Reformat the snapshot size into Gb
$snapsize = "{0,20:n3}" -f (($snapshot.Total*1024)/1GB)
$emailContent += "<tr><td>$($snapshot.ParentName)</td><td>$($snapshot.Name)</td><td>$($snapshot.AccessTime)</td><td>$($snapsize)GB</td></tr>"


$emailContent += "</table></body></html>"


# Generate the report and email it as a HTML body of an email
$SmtpClient = New-Object system.net.mail.smtpClient
$SmtpClient.host = $emailServer
$MailMessage = New-Object system.net.mail.mailmessage
#Change to email address you want emails to be coming from
$MailMessage.from = "storagereport@domain.com"
foreach($email in $emailNotifications) {
$MailMessage.To.add($email)
}
$MailMessage.Subject = "Netapp Offline Volume Report"
$MailMessage.IsBodyHtml = 1
$MailMessage.Body = $emailContent
$SmtpClient.Send($MailMessage)

Public