Microsoft Virtualization Discussions

get-nasnapmirror question

kurt_westenhoefer

I am trying to create a script that will list the snapmirror status for my filers and send the results to me in an e-mail.  When I type get-nasnapmirror FILERNAME it just brings me right back to the command prompt with no data returned.  I have also tried get-nasnapmirror FILERNAME:volume

If I type get-nasnapmirror by itself I get the result of a filer, but not the one I am trying to get.  I am not sure how or why it is going to that particular filer.

What am I doing wrong?

1 ACCEPTED SOLUTION

cknight

Hello, Kurt.  When you issue Connect-NaController, the resulting connection is cached in $global:CurrentNaController, and this value is used by all subsequent Toolkit cmdlet invocations unless you specifically provide the target using the -Controller parameter.

So to get Snapmirror relationships on a single controller, try:

Connect-NaController <controllerName>

Get-NaSnapmirror

To get Snapmirror relationships on a different controller, or in a loop context, try this:

$controller = Connect-NaController <controllerName>

Get-NaSnapmirror -Controller $controller

To get a specific relationship:


Get-NaSnapmirror -Location <sourceOrDestinationName> -Controller (Connect-NaController <controllerName>)

In this last case, the -Location parameter is just a string that matches the values returned by Get-NaSnapmirror or the values in /etc/snapmirror.conf.  Don't forget that you can use wildcards in the -Location parameter to expand your query results.  Also, nearly all Toolkit cmdlets have one or more examples in their online help, i.e. 'man Get-NaSnapmirror -Examples'.

View solution in original post

4 REPLIES 4

cknight

Hello, Kurt.  When you issue Connect-NaController, the resulting connection is cached in $global:CurrentNaController, and this value is used by all subsequent Toolkit cmdlet invocations unless you specifically provide the target using the -Controller parameter.

So to get Snapmirror relationships on a single controller, try:

Connect-NaController <controllerName>

Get-NaSnapmirror

To get Snapmirror relationships on a different controller, or in a loop context, try this:

$controller = Connect-NaController <controllerName>

Get-NaSnapmirror -Controller $controller

To get a specific relationship:


Get-NaSnapmirror -Location <sourceOrDestinationName> -Controller (Connect-NaController <controllerName>)

In this last case, the -Location parameter is just a string that matches the values returned by Get-NaSnapmirror or the values in /etc/snapmirror.conf.  Don't forget that you can use wildcards in the -Location parameter to expand your query results.  Also, nearly all Toolkit cmdlets have one or more examples in their online help, i.e. 'man Get-NaSnapmirror -Examples'.

View solution in original post

kurt_westenhoefer

Here is what I have so far.  I am stuck trying to get the results of this script in the body of the e-mail I am sending at the end of the script.  I can get it to output the results to the screen, but not in the body of the email.  Can someone tell me what I am doing wrong.  I am pretty new to PS so I am assuming I am missing something obvious.  I tried using Write-Output in the loop, but I couldn't get that to work either.

Import-Module DataONTAP

Connect-NAController netapp03

$sm = Get-NaSnapmirror

$SMTPSRV = "server.domain.com"

$EmailFrom = user@domain.com

$EmailTo = user@domain.com

foreach($sm in $sm) {

Write-Host $sm.SourceLocation "-->" $sm.DestinationLocation "-->" $sm.LagTime "-->" $sm.State "-->" $sm.Status

}

Send-MailMessage -To $EmailTo -Subject "Snapmirror Status" -Body "blahblahblah" -From $EmailFrom -SmtpServer $SMTPSRV

if your foreach loop you just need to add the results to a variable instead of doing a write-host.  Then reference that new variable as the body in the send-mailmessage command. For example:

foreach ($item in $collection) {

     $a += $item

}

Send-MailMessage -To $EmailTo -Subject "Snapmirror Status" -Body $a -From $EmailFrom -SmtpServer $SMTPSRV

that would get the job done but you can probably do a little bit more to format the information to make it more readable.

fjohn

One way to work with  multiple controllers in your loop is to create a collection of naconnection objects.  There's an example here: http://communities.netapp.com/docs/DOC-6293

J

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public