Microsoft Virtualization Discussions

E-mailing Output question

adamgross
3,819 Views

I a very simple script and I'd like to e-mail myself the output on a schedule...

-----/

connect-naserver san1

$vols = get-navol

Send-MailMessage -to $recipient -From $sender -Subject "Volume Report" -SmtpServer $smtpserver -Body "$vols"

/-----

I omitted the to/from/smtpserver string definitions since they don't matter.  When I just echo $vols I see the data I'd expect.  When I e-mail it to myself the body of the messages are:

NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume NetApp.SDK.NaVolume

Help would be appreciated so I can grab this at the same time every day without the risk of forgetting so I can have datapoints for trending.  Thanks!

1 ACCEPTED SOLUTION

cknight
3,819 Views

OK, Adam, that's progress.  You should have no further need for PoshOntap; the Toolkit has superseded that project and its author joined NetApp some time ago.

Your issue is that Get-NaVol writes objects to the pipeline, which are displayed in tabular format by default by the shell.  But you are sending the array of volume objects directly to the email.  To preserve the volume formatting as a string, try something like "$vols = Get-NaVol | Out-String".

View solution in original post

5 REPLIES 5

cknight
3,819 Views

Hi, Adam.  The Data ONTAP PowerShell Toolkit doesn't contain a cmdlet "connect-naserver" or a type "NetApp.SDK.NaVolume", so I'm not sure what you're using.  Whatever that is, it appears the NetApp.SDK.NaVolume class doesn't override ToString(); the equivalent class emitted by the Toolkit does.  Can you try with the Toolkit and let us know how that works?

adamgross
3,819 Views

Pretty sure I'm using the toolkit...  When connecting to a controller using Connect-NaController I get this message:

WARNING: @ Target Filer could not be found.

                              To avoid this error:

            1.) Pass the -server parameter

            2.) create a persistent connection with the Connect-NaServer cmdlet.

         We will now attempt to create a one time connection for you.

That's why I switched Connect-NaController to Connect-NaServer...

---

Edit:

When connecting, Connect-NaController works.  Commands after that point give the above error message.

adamgross
3,819 Views

I had a friend help me take a look at this and we found out that I had dataontap and poshontap modules loaded.  I have unloaded poshontap, which must have had a replacement Connect-NaController because my connection is persistent now.  Data is being gathered just as before, but I'm still experiencing the issue where console output and the e-mail body are not the same.

Console output:

Name                           State  TotalSize Used Available Dedupe FilesUsed FilesTotal Aggregate

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

vol0                           online   60.0 GB   6%   56.6 GB False        15k        10M SAS450GB_aggr0

E-mail body:

vol0

We're making progress.  The console has the chart with all of the information but the e-mail only has the name of the volume.

cknight
3,820 Views

OK, Adam, that's progress.  You should have no further need for PoshOntap; the Toolkit has superseded that project and its author joined NetApp some time ago.

Your issue is that Get-NaVol writes objects to the pipeline, which are displayed in tabular format by default by the shell.  But you are sending the array of volume objects directly to the email.  To preserve the volume formatting as a string, try something like "$vols = Get-NaVol | Out-String".

adamgross
3,819 Views

Awesome, adding "| Out-String" was the ticket.  It's nothing fancy obviously but here's the complete script.  It's handy for me so it might be handy for someone else.  Thanks a million for the help Clinton, this will save me a solid 45-60 minutes per day.  If you're ever in the Cincinnati area let me know, I owe you a few beers.

# Provide controller hostnames, IP's or FQDN's.  Add/remove additional as needed.

$filer1 = "xxx"

$filer2 = "xxx"

$filer3 = "xxx"

$filer4 = "xxx"

# Recipient e-mail address

$recipient = "xxx@somewhere"

# Sender e-mail address

$sender = "xxx@somewhere"

# Your SMTP server

$smtpserver = "mailserver"

$vols = $null

$line = "

"

Clear

Connect-NaController $filer1

$vols += Get-NaVol | Out-String

$vols += $line

Connect-NaController $filer2

$vols += Get-NaVol | Out-String

$vols += $line

Connect-NaController $filer3

$vols += Get-NaVol | Out-String

$vols += $line

Connect-NaController $filer4

$vols += Get-NaVol | Out-String

Send-MailMessage -to $recipient -From $sender -Subject "Volume Report" -SmtpServer $smtpserver -Body "$vols"

Public