Microsoft Virtualization Discussions
Microsoft Virtualization Discussions
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
Solved! See The Solution
*-Na* commands are for non cluster mode filers.
*-Na* commands are for non cluster mode filers.
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