Subscribe

Re: Powershell Lag Time

Josh, Add-NaCredential securely stores controller credentials in a local cache file.  If you don't explicitly provide credentials or specify -RPC, Connect-NaController consults the cache and uses any credentials found there.  So it's a great way to keep from having to prompt for credentials in an automated script job.  Like Eric said, if your automated job runs in a Windows user context other than your own, use "Add-NaCredential -SystemScope" to ensure other authenticated users on the local host can access the credentials store.

Re: Powershell Lag Time

Clinton,

I've been playing along with Add-nacredential.  Seems pretty cool.  Currently, the set of filers that i'm thinking about are not in the domain so that's why I am using -cred root.    I assume if I add the credentials to each filer on the local cache I need to use -systemscope especially if I am going to schedule the job as Local system in task manager.    The only bothering thing is that we need to update this when the root password changes.. Ugg..

Oh well, thx for the continued tips..

Re: Powershell Lag Time

I've adjusted the log file.  I didn't quite like using sc $outfile to xls. 

added out-string -width 4096 | out-file $outfile.

I had to use out-string b/c my volumes kept getting truncated b/c they were too long.  I had to change the default behavior of the display window.  Just make sure you adjust $ext to $ext = ".log"

Re: Powershell Lag Time

Hi Eric,

I had similar requirement, i.e i want lag time of only specific volumes, and want output directly on email.

i have modified the script but i am not able to get specific volume, can you please advice me on this.

### Mail "constants"

      $sendMailAs    = ""

       $recipients    = ""

       $subjectLine = ""

       $mailMessage = ""

       $smtpServer = ""

       $priority = "high"

### Import Data OnTap Module

    # Check toolkit version

    try

    {

        if (-Not (Get-Module DataONTAP))

        {

            Import-Module DataONTAP -EA 'STOP' -Verbose:$false

        }

        if ((Get-NaToolkitVersion).CompareTo([system.version]'1.7') -LT 0) { throw }

    }

    catch [Exception]

    {

        Write-Warning "This script requires Data ONTAP PowerShell Toolkit 1.7 or higher."

        return;

    }

### Define Lag time

$lagtimeseconds = "3600" #One hour lagtime

### Input File properties

$hostfile = "C:\Powershell Script\hosts.txt"

$accnt = ""

$filerpassw = ""

$password = ConvertTo-SecureString $filerpassw -AsPlainText –Force 

$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $accnt,$password 

$snapMirrors = @()

gc $hostfile | % {

  $C = Connect-NaController -credential $cred $_

  $snapMirrors +=  Get-NaSnapmirror | where-object {$_.lagTime -gt $lagTimeSeconds} | Select SourceLocation ,DestinationLocation,Status,State,LagtimeTS # |  ft @{expression={$c};Label="Filer name";width=20},@{expression={$_.SourceLocation};Label="Source";Width=40},@{Expression={$_.DestinationLocation};Label="Destination";Width=40},@{expression={$_.status};Label="status";width=20},@{Expression={$_.state};Label="state";width=20},@{Expression={$_.lagtimets};label="lag time";width=20}

 

}

$dataToWrite = $snapMirrors | out-string -width 4096

 

## Send Email

Send-MailMessage -To $recipients -From $sendMailAs -Subject $subjectLine -Body $dataToWrite -Priority $priority -SmtpServer $smtpServer

exit 4

#####

Re: Powershell Lag Time

You gotta give me a little more information here....   You can query based on volume name if you want, but do all your filers that you want have the same name.

You can do something like

get-navol | ? {$_.name -like "*nameyouwant*"} | get-nasnapmirror

Or you can filter get-nasnapmirror or you can do a where-object on $_.destination ..

Re: Powershell Lag Time

Hi,

i want output only from destination filer and there is only 1 destination filer.

i want only specific volumes in the list. i will try the query you have given.

Also i am facing 1 problem, in output all the volumes are not getting displayed, there are certain volumes which are not displayed.

Thanks

Re: Powershell Lag Time

Hi,

seems its working now with below script.

still i am not able to figure out 1) in output i want name of the volume and 2) lag time in minutes.

can you please let me know how can i get this.

### Mail "constants"

      $sendMailAs    = ""

       $recipients    = ""

       $subjectLine = ""

       $mailMessage = ""

       $smtpServer = ""

       $priority = ""

### Import Data OnTap Module

    # Check toolkit version

    try

    {

        if (-Not (Get-Module DataONTAP))

        {

            Import-Module DataONTAP -EA 'STOP' -Verbose:$false

        }

        if ((Get-NaToolkitVersion).CompareTo([system.version]'1.7') -LT 0) { throw }

    }

    catch [Exception]

    {

        Write-Warning "This script requires Data ONTAP PowerShell Toolkit 1.7 or higher."

        return;

    }

### Define Lag time

$lagtimeseconds = "3600" #One hour lagtime

### Input File properties

$hostfile = "C:\Powershell Script\hosts.txt"

$accnt = ""

$filerpassw = ""

$password = ConvertTo-SecureString $filerpassw -AsPlainText –Force 

$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $accnt,$password 

$snapMirrors = @()

gc $hostfile | % {

  $C = Connect-NaController -credential $cred $_

  $snapMirrors +=   Get-NaSnapmirror | where-object {$_.destination -like "name"} | Select SourceLocation,DestinationLocation,Status,LagtimeTS  |  ft -AutoSize @{expression={$_.SourceLocation};Label="Source";Width=40},@{Expression={$_.DestinationLocation};Label="Destination";Width=40},@{expression={$_.status};Label="status";width=20},@{Expression={$_.lagtimets};label="lag time";width=20}

 

}

$dataToWrite = $snapMirrors | out-string -Width 4096

#$dataToWrite | sc $outfile

 

## Send Email

Send-MailMessage -To $recipients -From $sendMailAs -Subject $subjectLine -Body $dataToWrite -Priority $priority -SmtpServer $smtpServer

exit 4

#####

Re: Powershell Lag Time

Well you can use the below.. This is what i use as of today

gc $hostfile | % {

    $C = Connect-NaController  $_

    $snapMirrors = Get-NaSnapmirror | Where-Object {$_.lagTime -gt $lagtimeseconds}

    if ($snapMirrors -ne $null)

    {

     $snapMirrors | ft @{expression={$C};Label="Filer";Width=10},@{expression={$_.sourcelocation};Label="Source";Width=20}`

    ,@{expression={$_.destinationlocation};Label="Destination Location";Width=20},@{expression={$_.state};Label="Current State";Width=20}`

    ,@{N='Current Lag Time';E={'{0} days, {1} hrs, {2} mins, {3} secs' -f $_.LagTimeTS.days, $_.LagTimeTS.Hours, $_.LagTimeTS.Minutes, $_.LagTimeTS.Seconds}}`

    ,@{expression={ConvertTo-FormattedNumber $_.transferprogress DataSize "0.0"};Label="Current Progress";Width=20}`

    ,@{expression={ConvertTo-FormattedNumber $_.lasttransfersize Datasize "0.0"};Label="Last Transfer size";Width=20} -autosize `

    |  Out-String -Width 4096 | Out-File $totaloutfile -append

}

}

Re: Powershell Lag Time

Script you mentioned is not working.

i am using below script and its working fine though i need some modification in it.

1) i am able to filter 1 volume using query but i want to filter list of volumes which are mentioned in file.

2) lag time should be only in minutes.

3) i want name of volume in output which is not happening.

$snapMirrors = @()

gc $hostfile | % {

  $C = Connect-NaController -credential $cred $_

    $snapMirrors +=   Get-NaSnapmirror | where-object {$_.destination -like } | Select VOLNAME,DestinationLocation,Status,LagtimeTS  |  ft -AutoSize @{expression={$_.VOLNAME};Label="Volume";Width=40},@{Expression={$_.DestinationLocation};Label="Destination";Width=40},@{expression={$_.status};Label="status";width=20},@{expression={$_.lagtimets};Label="lagtime";width=20}

}

Thanks in advance.

Re: Powershell Lag Time

Ok, I didn't post the entire script, just a snippet... 

What I posted is exactly what your looking for...