Microsoft Virtualization Discussions

Using module dataontap - and scripting with cmdlet Get-nasnapmirrorschedule

thaddad
1,305 Views

I have a script that runs get-ncvol ...the connect... and get-ncvol work fine.  I want to get some snapmirror info with 

"get-nasnapmirrorschedule"  Seems it requires credentialsparameter??!.   Does anyone know what the format of get-nassnapmirrorschedule is?

$username = "xxxxx"
$pwdTxt = Get-Content "C:\Scripts\Storage\xxxxx.txt"
$securePwd = $pwdTxt | ConvertTo-SecureString
$credObject = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $securePwd

$global:CurrentNcController = $null

connect-nccontroller $cluster -credential $credObject

get-ncvol

**********************************************

I tried to use "get-nasnapmirrorschedule -Controller xxxx"  and it errors...wanting credentials. 

get-nasnapmirrorschedule : Incorrect credentials for xxxxx
At C:\scripts\storage\testing-snapmirror\Snapmirror-check.ps1:32 char:1
+ get-nasnapmirrorschedule -Controller xxxxx
+ CategoryInfo : InvalidOperation: (bmina:NaController) [Get-NaSnapmirrorSchedule], NaAuthException
+ FullyQualifiedErrorId : ApiException,DataONTAP.PowerShell.SDK.Cmdlets.Snapmirror.GetNaSnapmirrorSchedule

1 ACCEPTED SOLUTION

RobDBA
1,077 Views

*-Na* commands are for non cluster mode filers.

View solution in original post

3 REPLIES 3

RobDBA
1,078 Views

*-Na* commands are for non cluster mode filers.

mbeattie
880 Views

Hi,

 

If the CmdLet in the PSTK is not working as you expect you can always use the REST API. Here's an example of enumerating the schedules in ONTAP. I suspect there is a bug in the "Get-NaSnapMirrorSchedule" CmdLet in the latest PSTK version in the "NetApp.ONTAP" module. You can also invoke a CLI via the REST API if you prefer.

 

 

Param(
   [Parameter(Mandatory = $True, HelpMessage = "The cluster name or IP Address")]
   [String]$Cluster,
   [Parameter(Mandatory = $True, HelpMessage = "The Credential to authenticate to ONTAP")]
   [ValidateNotNullOrEmpty()]
   [System.Management.Automation.PSCredential]$Credential
)
#'------------------------------------------------------------------------------
Function Get-NrAuthorization{
   [Alias("Get-UMAuth")]
   [CmdletBinding()]
   Param(
      [Parameter(Mandatory = $True, HelpMessage = "The Credential to authenticate to ONTAP")]
      [ValidateNotNullOrEmpty()]
      [System.Management.Automation.PSCredential]$Credential
   )
   #'---------------------------------------------------------------------------
   #'Set the authentication header to connect to ONTAP.
   #'---------------------------------------------------------------------------
   $auth    = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($Credential.UserName + ':' + $Credential.GetNetworkCredential().Password))
   $headers = @{
      "Authorization" = "Basic $auth"
      "Accept"        = "application/json"
      "Content-Type"  = "application/json"
   }
   Return $headers;
}#'End Function Get-NrAuthorization.
#'------------------------------------------------------------------------------
Function Get-NrSchedule{
   [CmdletBinding()]
   Param(
      [Parameter(Mandatory = $True, HelpMessage = "The cluster name or IP Address")]
      [String]$Cluster,
      [Parameter(Mandatory = $True, HelpMessage = "The Credential to authenticate to ONTAP")]
      [ValidateNotNullOrEmpty()]
      [System.Management.Automation.PSCredential]$Credential
   )
   #'---------------------------------------------------------------------------
   #'Set the authentication header to connect to ONTAP.
   #'---------------------------------------------------------------------------
   $headers = Get-NrAuthorization -Credential $Credential
   #'---------------------------------------------------------------------------
   #'Enumerate the Schedules.
   #'---------------------------------------------------------------------------
   [String]$uri = "https://$Cluster/api/cluster/schedules"
   Try{
      $response = Invoke-RestMethod -Uri $uri -Method GET -Headers $headers -ErrorAction Stop
      Write-Host "Enumerated Schedules on Cluster ""$Cluster"" using URI ""$uri"""
   }Catch{
      Write-Warning -Message $("Failed enumerating Schedules on Cluster ""$Cluster"" using URI ""$uri"". Error " + $_.Exception.Message + ". Status Code " + $_.Exception.Response.StatusCode.value__)
   }
   Return $response;
}#'End Function Get-NrSchedule.
#'------------------------------------------------------------------------------
#'Enumerate the schedules on the cluster.
#'------------------------------------------------------------------------------
Try{
   $schedules = Get-NrSchedule -Cluster $Cluster -Credential $Credential -ErrorAction Stop
   Write-Host "Enumerated schedules on cluster ""$Cluster"""
}Catch{
   Write-Warning -Message $("Failed enumerating schedules on cluster ""$Cluster"". Error " + $_.Exception.Message)
   Exit -1;
}
$schedules.records
#'------------------------------------------------------------------------------

 

 

Here is an example of syntax:

 

PS E:\Scripts\PowerShell\Projects\GetSnapMirrorSchedule> .\GetSnapMirrorSchedule.ps1 -Cluster 192.168.100.2 -Credential $credential
Enumerated Schedules on Cluster "192.168.100.2" using URI "https://192.168.100.2/api/cluster/schedules"
Enumerated schedules on cluster "192.168.100.2"

uuid                                 name                                  cron
----                                 ----                                  ----
0adb64c1-8374-11ee-8d03-00a098ba68d6 8hour                                 @{minutes=System.Object[]; hours=System.Object[]}
0ae0899e-8374-11ee-8d03-00a098ba68d6 hourly                                @{minutes=System.Object[]}
0ae2a527-8374-11ee-8d03-00a098ba68d6 5min                                  @{minutes=System.Object[]}
0aef6a2e-8374-11ee-8d03-00a098ba68d6 daily                                 @{minutes=System.Object[]; hours=System.Object[]}
0af386e5-8374-11ee-8d03-00a098ba68d6 weekly                                @{minutes=System.Object[]; hours=System.Object[]; weekdays=System.Object[]}

 

Hope that helps

 

/Matt

If this post resolved your issue, help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

thaddad
851 Views
Thank you. Also I ran Get-Ncsnapmirrorschedule without any parameters (after doint a Connect... to the cluster) and all was successful

Tom Haddad
Office of Technology - Storage Administration
Encova Insurance
400 Quarrier Street
Charleston, Wv 25301
Encova.com
Tom.haddad@encova.com
Office 304 220 6776
Mobile 304 542 1876





Important notice: This message may contain confidential information intended exclusively for the recipient named above. If you have received this email in error, or if you are not the intended recipient, please promptly delete and destroy the original email transmission. Any unauthorized use, dissemination, distribution or duplication of this email message is strictly prohibited. Thank you for your assistance.
Public