ONTAP Discussions

The New-NcSnapMirror command in powershell - "Incorrect credential problem"

Northman
1,263 Views

I will soon have to give up using Powershell to setup hundreds of SM relationships. I established peer relationships between the two SVMs, and in the GUI I can setup SnapMirror on the destination if I want. But I will have to do it one-by-one. This is why I am trying to do it with Powershell. I am using the New-NCSnapMirror command in order to create the relationship. But it stops due to "Incorrect credenials" on the destination cluster. But as you can see from the attachment, I am already connected to the destination cluster. Why is it saying the credential is wrong? 

 

Please see my attachment showing the command with -debug turned on.

3 REPLIES 3

NetappUser117
307 Views

I second this. I get the exact same issue. Perhaps it's a bug in the command itself.

mbeattie
280 Views

Hey,

 

I tested the CmdLet. If you have used the Connect-NcController to connect to the destination cluster you don't need to pass the -Controller parameter (as it will use the current connection). EG:

 

PS C:\Scripts\PowerShell\Projects\ONTAP\CreateSnapMirrorCLI> connect-nccontroller -Name cluster2 -Credential $credential

Name                 Address           Vserver              Version
----                 -------           -------              -------
cluster2             192.168.0.102                          NetApp Release Clawhammer__9.14.1: Tue Mar 19 18:52:51 UTC 2024

PS C:\Scripts\PowerShell\Projects\ONTAP\CreateSnapMirrorCLI> New-NcSnapmirror -DestinationCluster cluster2 -DestinationVserver svm1_cluster2 -DestinationVolume volume_002_dr -SourceCluster cluster1 -SourceVserver svm1_cluster1 -SourceVolume volume_002 -Type DP

SourceLocation                                DestinationLocation                           Status       MirrorState
--------------                                -------------------                           ------       -----------
svm1_cluster1:volume_002                      svm1_cluster2:volume_002_dr                   uninitial... uninitialized

 

The private REST CLI example might come in useful for tasks that might not have a corresponding PowerShell CmdLet in future. Certainly useful to know about.

 

Hope that helps

 

/Matt

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

mbeattie
281 Views

Hi Guys,

 

I'm not sure if there's an issue with the CmdLet however you could use the private REST CLI as an alternative. Here is an example for you:

Param(
   [Parameter(Mandatory = $True, HelpMessage = "The destination cluster name or IP Address")]
   [String]$Cluster,
   [Parameter(Mandatory = $True, HelpMessage = "The Source Vserver name")]
   [String]$SourceVserver,
   [Parameter(Mandatory = $True, HelpMessage = "The Source Volume name")]
   [String]$SourceVolume,
   [Parameter(Mandatory = $True, HelpMessage = "The destination Vserver name")]
   [String]$TargetVserver,
   [Parameter(Mandatory = $True, HelpMessage = "The destination Volume name")]
   [String]$TargetVolume,
   [Parameter(Mandatory = $True, HelpMessage = "The Schedule name")]
   [String]$ScheduleName,
   [Parameter(Mandatory = $True, HelpMessage = "The Policy name")]
   [String]$PolicyName,
   [Parameter(Mandatory = $True, HelpMessage = "The Relationship type")]
   [ValidateSet("DP","LS","XDP","TDP")]
   [String]$RelationshipType,
   [Parameter(Mandatory = $True, HelpMessage = "The Credentials to authenticate to the destination cluster")]
   [System.Management.Automation.PSCredential]$Credential
)
#'------------------------------------------------------------------------------
#'Set the certificate policy and TLS version.
#'------------------------------------------------------------------------------
Add-Type @"
   using System.Net;
   using System.Security.Cryptography.X509Certificates;
   public class TrustAllCertsPolicy : ICertificatePolicy {
   public bool CheckValidationResult(
   ServicePoint srvPoint, X509Certificate certificate,
   WebRequest request, int certificateProblem) {
      return true;
   }
}
"@
[System.Net.ServicePointManager]::SecurityProtocol  = [System.Net.SecurityProtocolType]'Tls12'
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
#'------------------------------------------------------------------------------
Function Get-NcAuthorization{
   [Alias("Get-NcAuth")]
   [CmdletBinding()]
   Param(
      [Parameter(Mandatory = $True, HelpMessage = "The Credential to authenticate to the cluster")]
      [ValidateNotNullOrEmpty()]
      [System.Management.Automation.PSCredential]$Credential
   )
   #'---------------------------------------------------------------------------
   #'Set the authentication header to connect to the cluster.
   #'---------------------------------------------------------------------------
   $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-NcAuthorization.
#'------------------------------------------------------------------------------
[String]$command = "snapmirror create -source-path '$SourceVserver`:$SourceVolume' -destination-path '$TargetVserver`:$TargetVolume' -schedule $ScheduleName -policy $PolicyName -type $RelationshipType "
$headers = Get-NcAuth -Credential $Credential
$cli = @{};
$cli.Add("source-path", "$SourceVserver`:$SourceVolume")
$cli.Add("destination-path", "$TargetVserver`:$TargetVolume")
$cli.Add("schedule", $ScheduleName)
$cli.Add("policy", $PolicyName)
$cli.Add("type", $RelationshipType)
$body = $cli | ConvertTo-Json
#'------------------------------------------------------------------------------
#'Create the SnapMirror relationship and set the schedule.
#'------------------------------------------------------------------------------
[String]$uri = "https://$Cluster/api/private/cli/snapmirror"
Write-Host "Executing Command`: $command"
Try{
   $response = Invoke-RestMethod -Method Post -Body $body -Uri $uri -Headers $headers -ErrorAction Stop
}Catch{
   Write-Warning -Message $("Failed Creating SnapMirror relationship between ""$SourceVserver`:$SourceVolume"" and ""$TargetVserver`:$TargetVolume"" on cluster ""$Cluster"". Error " + $_.Exception.Message)
   Break;
}
If($Null -ne $response){
   If($response -Match "Operation succeeded"){
      Write-Host "Created SnapMirror relationship between ""$SourceVserver`:$SourceVolume"" and ""$TargetVserver`:$TargetVolume"" on cluster ""$Cluster"""
   }Else{
      Write-Warning -Message "Failed Creating SnapMirror relationship between ""$SourceVserver`:$SourceVolume"" and ""$TargetVserver`:$TargetVolume"" on cluster ""$Cluster"""
      Break;
   }
}Else{
   Write-Warning -Message "Failed Creating SnapMirror relationship between ""$SourceVserver`:$SourceVolume"" and ""$TargetVserver`:$TargetVolume"" on cluster ""$Cluster"""
   Break;
}
#'------------------------------------------------------------------------------

 

Usage:

 

PS C:\Scripts\PowerShell\Projects\ONTAP\CreateSnapMirrorCLI> $credential = Get-Credential
PS C:\Scripts\PowerShell\Projects\ONTAP\CreateSnapMirrorCLI> .\CreateSnapMirrorCLI.ps1 -Cluster cluster2 -SourceVserver svm1_cluster1 -SourceVolume volume_001 -TargetVserver svm1_cluster2 -TargetVolume volume_001_dr -ScheduleName daily -PolicyName DPDefault -RelationshipType DP -Credential $credential
Executing Command: snapmirror create -source-path 'svm1_cluster1:volume_001' -destination-path 'svm1_cluster2:volume_001_dr' -schedule daily -policy DPDefault -type DP
Created SnapMirror relationship between "svm1_cluster1:volume_001" and "svm1_cluster2:volume_001_dr" on cluster "cluster2"

Hope that helps

 

/Matt

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