Automating Netapp Volume reporting using Powershell Toolkit

Simple Powershell Script to automate the process of gathering volume details on a single filer, or group of filers.

 

The Script pulls the below information from the controller, the Script can be executed as it is and does not use the concepts of  advanced functions or modularization.

 

VolumeName TotalSize(GB) AvailableSize(GB) UsedSize(GB) SnapshotBlocksReserved(GB) SnapshotPercentReserved Aggregate IsDedupeEnabled Type DiskCount RaidStatus Autosize ChecksumStyle State

 

Script will output files in Location Specified The csv files would be saved with a filename of <controller>.csv .

 

Script will check if these files exist before creating new ones and will delete them if they do exist.

 

Script assumes same set of credentials for each filer specified.

 

Example :-

 

.\netapp_volume_report.ps1 -Controller 10.238.187.42,10.238.187.50 -UserName root -Password auskit! -Location "c:\vinith\powershell"

 

 

Attached you can the sample csv files generated and also the script.

Comments

Sweet script! can you configure it so its able to send email? I want to run it as a daily task

reide Former NetApp Employee

Very nice.  There are times where reports in OnCommand Unified Manager or other tools just don't accomodate a customer's need.  The ability to create these reports with the ONTAP PowerShell Toolkit is a great way to help customers work-around this.

vinith Former NetApp Employee

Hi Skip, If you are in PowerShell v3 then you can use a new module called PowerShell Scheduled jobs where you can trigger a job to trigger using.

Just Copy paste the entire script into an powershell window open in administrative mode and make changes below which are highlighted in Bold

# Setting the Trigger Time to Run, here we have set the trigger to run daily at 6am

$trigger = New-JobTrigger -Daily -At 6am

 

# Registering a Scheduled job called get-volumeinfo and attaching a script block with a trigger

Register-ScheduledJob -Name Get-VolumeInfo -Trigger $trigger -ScriptBlock {

Import-Module DataONTAP -ErrorAction SilentlyContinue

$ControllerPassword = ConvertTo-SecureString -String "565^666" -AsPlainText -force

$ControllerCredential = New-Object System.Management.Automation.PsCredential("root",$ControllerPassword)

# Enter The Controller Names separated by Comma

$controller = @('10.238.187.42','10.238.187.50')

 

Foreach ($filer in $controller)

{

 

Connect-NaController -Name $filer -Credential $ControllerCredential

Write-Verbose "Collecting Volume Information for $filer" -Verbose

Get-NaVol | Select @{Name="VolumeName";Expression={$_.name}},@{Name="TotalSize(GB)";Expression={[math]::Round([decimal]$_.SizeTotal/1gb,2)}},@{Name="AvailableSize(GB)";Expression={[math]::Round([decimal]$_.SizeAvailable/1gb,2)}},@{Name="UsedSize(GB)";Expression={[math]::Round([decimal]$_.SizeUsed/1gb,2)}},@{Name="SnapshotBlocksReserved(GB)";Expression={[math]::Round([decimal]$_.SnapshotBlocksReserved/1gb,2)}}`

,SnapshotPercentReserved,Aggregate,IsDedupeEnabled,type,DiskCount,RaidStatus,Autosize,ChecksumStyle,state | Export-Csv -LiteralPath $Location\$filer.csv -Force -NoTypeInformation -Verbose

Write-Verbose "Completed Collecting Volume Information for $filer" -Verbose

 

}

# Here i have kept all files generated in "C:\Vinith\powerShell\New folder"

 

$filenames = Get-ChildItem "C:\Vinith\powerShell\New folder\*" | select -ExpandProperty fullname

 

foreach ( $file in $filenames )

{

 

$smtpServer = "HUB"

$att = new-object Net.Mail.Attachment($file)

$msg = new-object Net.Mail.MailMessage

$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$SMTP.EnableSsl = $true

$SMTP.Credentials = New-Object System.Net.NetworkCredential("test\vinith", "trtasrt$");

#$SMTP.Send($EmailFrom, $EmailTo, $Subject, $Body)

#$msg.To.Add("administrator2@test.com")

$msg.From = "vinith@test.com"

$msg.To.Add("vinith@test.com")

$msg.Subject = "Notification from Controller $file"

$msg.Body = "Attached is the Controller Volume report"

$msg.Attachments.Add($att)

$smtp.Send($msg)

}

}

I will definitely be using this as one of my goto scripts. Thanks for posting.

vinith Former NetApp Employee

Hi Skip, did you modify the contents marked in bold in my scheduling script??

Please modify the bold contents marked below and give it a try, these values should be replaced with the corresponding values for your environment

$ControllerPassword = ConvertTo-SecureString -String "565^666" -AsPlainText -force

$ControllerCredential = New-Object System.Management.Automation.PsCredential("root",$ControllerPassword)

$controller = @('10.238.187.42','10.238.187.50')

$filenames = Get-ChildItem "C:\Vinith\powerShell\New folder\*" | select -ExpandProperty fullname

$smtpServer = "HUB"

$SMTP.Credentials = New-Object System.Net.NetworkCredential("test\vinith", "trtasrt$");

$msg.From = "vinith@test.com"

$msg.To.Add("vinith@test.com")





vinith Former NetApp Employee

Great!

Great script!  Thank you.

I had to make a minor modification to make it work on my system.  Line 29 I had to remove the '-LiteralPath'parameter .  So I change the 'Export-Csv' statement from:

Export-Csv -LiteralPath $Location\$filer.csv -Force -NoTypeInformation -Verbose

to

Export-Csv $Location\$filer.csv -Force -NoTypeInformation -Verbose

Prior to that I was receiving this error:

Export-Csv : A parameter cannot be found that matches parameter name 'LiteralPath'.

At C:\Users\username\Documents\scripts\netapp_volume_report.ps1:29 char:132

+ ,SnapshotPercentReserved,Aggregate,IsDedupeEnabled,type,DiskCount,RaidStatus,Autosize,ChecksumStyle,state | Export-Cs

v -LiteralPath <<<<  $Location\$filer.csv -Force -NoTypeInformation -Verbose

    + CategoryInfo          : InvalidArgument: (Smiley Happy [Export-Csv], ParameterBindingException

    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.ExportCsvCommand

Hello Vinith

Yes i modifed this parts of the script that were in BOLD, however when i run the script i get an error

,SnapshotPercentReserved,Aggregate,IsDedupeEnabled,type,DiskCount,RaidStatus,Aut ...


Missing expression after unary operator ','.


At C:\Scripts\netapp_volume_report.ps1\test11.ps1:39 char:2

Also when i run the original script that you posted that does not contain the scheduled task, the script runs without  errors.

If i  remove the space on line 38 of the script, after doing this the script does create the scheduled task, and i do not recieve the above mentioned error. Now i will try and run the script as a scheduled task.

Ok, i am able to run the script as a scheduled task, and that is fantastic! however the script is putting the files on the root of the C:\ drive instead of the directory that i configured the script to output the .csv files to. I edited the below part of the script in an effort to store the .csv files in the temp dir

$filenames = Get-ChildItem "C:\temp\*" | select -ExpandProperty fullname

since i wasnt able to figure out how to modify the script to output the files in the C:\temp dir, i changed the below line in the script and now its working great!  My netapp filers all start with irvdcna*

$filenames = Get-ChildItem "C:\irvdcna*" | select -ExpandProperty fullname

vinith Former NetApp Employee

NIce to Know it worked.

Hi, This is very useful script. I want to modify this to export a volumes report for my environment.

Can anybody help me to modify the script if I can't extract volumes report for volumes starting from "gss". So volumes including gss1, gss2 gss_abc etc.

And also could you tell me how to extract filers name in the first column in each line?

This is exactly what I am looking for! 

Is there a C-DOT version? We are transitioining currently.

rw

nice script except, you prompt for the password, which when typed in appears in plain text you should use Get-Credential command instead, just a thought.

I noticed that SnapshotBlocksReserved returned by Get-NaVol appears to be presented in KB, not bytes, as the other values are. All my numbers come out correctly if I assume it is in KB.

 

Hello All,

 

it's working also for Cluster-Mode. With some differences like

 

Connect-NcController

instead of

 

Connect-NaController

 

param(  
        [Parameter(Mandatory=$true,ValueFromPipeline=$True,HelpMessage="Enter the FQDN of your NetApp Cluster-MODE Controller")]  
        $Controller,
        [Parameter(Mandatory=$true,ValueFromPipeline=$True,HelpMessage="Enter the Username for Accessing the Controller")]  
        $UserName,
        [Parameter(Mandatory=$true,ValueFromPipeline=$True,HelpMessage="Enter the Password for Accessing the Controller")]  
        $Password,
        [Parameter(Mandatory=$true,ValueFromPipeline=$True,HelpMessage="Enter the Location to save the csv file")]  
        $Location          
      )

cd "C:\Program Files (x86)\NetApp\Data ONTAP PowerShell Toolkit\DataONTAP"
Import-Module DataONTAP -ErrorAction SilentlyContinue

$ControllerPassword = ConvertTo-SecureString -String $Password -AsPlainText -force
$ControllerCredential = New-Object System.Management.Automation.PsCredential($UserName,$ControllerPassword)

Foreach ($node in $controller){
    Connect-NcController -Name $node -Credential $ControllerCredential
    Write-Verbose "Collecting Volume Information for $node" -Verbose
    Get-NcVol | Select-object name,state,Totalsize,Used,Available,Aggregate,Vserver | Export-Csv $Location\$node.csv -Delimiter ";"-Force -NoTypeInformation -Verbose
    Write-Verbose "Completed Collecting Volume Information for $node" -Verbose
}

 

Ran the script, received the following error.

 

PS C:\> .\netapp_volume_report.ps1 -Controller 10.5.52.51,10.5.52.52 -UserName root -Password XXXXXX -Location "C:\Net
AppReports"

Name Address Ontapi Version
---- ------- ------ -------
10.5.52.51 10.5.52.51 1.19 NetApp Release 8.1.2P4 7-Mode: Fri Apr 26 19:57:25 PDT 2013
VERBOSE: Collecting Volume Information for 10.5.52.51
Export-Csv : A parameter cannot be found that matches parameter name 'LiteralPath'.
At C:\netapp_volume_report.ps1:29 char:132
+ ,SnapshotPercentReserved,Aggregate,IsDedupeEnabled,type,DiskCount,RaidStatus,Autosize,ChecksumStyle,state | Export-Cs
v -LiteralPath <<<< $Location\$filer.csv -Force -NoTypeInformation -Verbose
+ CategoryInfo : InvalidArgument: (Smiley Happy [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.ExportCsvCommand

VERBOSE: Completed Collecting Volume Information for 10.5.52.51
10.5.52.52 10.5.52.52 1.19 NetApp Release 8.1.2P4 7-Mode: Fri Apr 26 19:57:25 PDT 2013
VERBOSE: Collecting Volume Information for 10.5.52.52
Export-Csv : A parameter cannot be found that matches parameter name 'LiteralPath'.
At C:\netapp_volume_report.ps1:29 char:132
+ ,SnapshotPercentReserved,Aggregate,IsDedupeEnabled,type,DiskCount,RaidStatus,Autosize,ChecksumStyle,state | Export-Cs
v -LiteralPath <<<< $Location\$filer.csv -Force -NoTypeInformation -Verbose
+ CategoryInfo : InvalidArgument: (Smiley Happy [Export-Csv], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.ExportCsvCommand

VERBOSE: Completed Collecting Volume Information for 10.5.52.52

I am getting the following error:

 

 

PS C:\Users\falam1\Desktop\Script> .\netapp_volume_report.ps1

Security Warning
Run only scripts that you trust. While scripts from the Internet can be useful, this script can potentially harm your
computer. Do you want to run C:\Users\falam1\Desktop\Script\netapp_volume_report.ps1?
[D] Do not run [R] Run once [S] Suspend [?] Help (default is "D"): R

cmdlet netapp_volume_report.ps1 at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
Controller: n-3270-4869-4b.etc.uspto.gov
UserName: 
Password: 
Location: C:\Users\falam1\Desktop\New
The term 'Connect-NaController' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\falam1\Desktop\Script\netapp_volume_report.ps1:22 char:21
+ Connect-NaController <<<< -Name $filer -Credential $ControllerCredential
+ CategoryInfo : ObjectNotFound: (Connect-NaController:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

VERBOSE: Collecting Volume Information for n-3270-4869-4b.etc.uspto.gov
The term 'Get-NaVol' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the s
pelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\falam1\Desktop\Script\netapp_volume_report.ps1:28 char:10
+ Get-NaVol <<<< | Select @{Name="VolumeName";Expression={$_.name}},@{Name="TotalSize(GB)";Expression={[math]::Round([
decimal]$_.SizeTotal/1gb,2)}},@{Name="AvailableSize(GB)";Expression={[math]::Round([decimal]$_.SizeAvailable/1gb,2)}},@
{Name="UsedSize(GB)";Expression={[math]::Round([decimal]$_.SizeUsed/1gb,2)}},@{Name="SnapshotBlocksReserved(GB)";Expres
sion={[math]::Round([decimal]$_.SnapshotBlocksReserved/1gb,2)}}`
+ CategoryInfo : ObjectNotFound: (Get-NaVol:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

VERBOSE: Completed Collecting Volume Information for n-3270-4869-4b.etc.uspto.gov

 

 

Please help.

Does it work for cDOT ? can someone give me similar cDOT script ,

 

I saw someone said it works for cDOT, but what modifications are needed ?

 

Thanks.

Hello,

 

There is one missing thing in script:

 

$Location = "C:\Vinith\powerShell\New folder"

 

Hope that helps somebody Smiley Happy

How to send all the o/p files in a location all together, I have collected individual reports for Volumes, Aggregate, disks, qtrees. Also, please let me know ss there a way to export all the o/ps to a single file by adding individual tab ?