Microsoft Virtualization Discussions
Microsoft Virtualization Discussions
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?
Solved! See The Solution
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'.
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'.
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
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.