<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: dataontap module - using powershell to invoke abort on all active snapmirror sessions in ONTAP Discussions</title>
    <link>https://community.netapp.com/t5/ONTAP-Discussions/dataontap-module-using-powershell-to-invoke-abort-on-all-active-snapmirror/m-p/453121#M43673</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a script that using the private REST CLI to enumerate all snapmirror relationships that are in a transferring state and abort them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Param(
    [Parameter(Mandatory = $True, HelpMessage="The Destination Cluster name or IP Address")]
    [String]$Cluster,
    [Parameter(Mandatory = $False, HelpMessage = "The Credentials to authenticate to ONTAP")]
    [System.Management.Automation.PSCredential]$Credential
)
#'------------------------------------------------------------------------------
Function Get-OntapAuthorization{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory = $True, HelpMessage = "The Credential to authenticate to the ONTAP 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-OntapAuthorization.
#'------------------------------------------------------------------------------
Function Invoke-OntapRestCli{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory = $True, HelpMessage = "The Cluster Name or IP Address")]
        [String]$Cluster,
        [Parameter(Mandatory = $True, HelpMessage = "The REST API Method to Invoke")]
        [ValidateSet("get","patch","post","delete")]
        [String]$Method,
        [Parameter(Mandatory = $False, HelpMessage = "The JSON payload used for creating or modifying an object")]
        [String]$Body,
        [Parameter(Mandatory = $True, HelpMessage = "The URI to invoke")]
        [String]$Uri,
        [Parameter(Mandatory = $True, HelpMessage = "The Credential to authenticate to the Cluster")]
        [ValidateNotNullOrEmpty()]
        [System.Management.Automation.PSCredential]$Credential
    )
    #'--------------------------------------------------------------------------
    #'Exit if the body is not provided when calling the post or patch method.
    #'--------------------------------------------------------------------------
    If(($Method -eq "post" -Or $Method -eq "patch") -And ($Null -eq $Body)){
        Write-Warning -Message "The body parameter must be provided when invoking the patch or post method"
        Return $Null;
    }
    #'--------------------------------------------------------------------------
    #'Add the CLI privilege Level to the command and set the Authentication header.
    #'--------------------------------------------------------------------------
    $headers = Get-OntapAuthorization -Credential $Credential
    #'--------------------------------------------------------------------------
    #'Invoke the command via the private REST CLI.
    #'--------------------------------------------------------------------------
    Try{
        If($Method -eq "post" -Or $Method -eq "patch"){
            $bodyJson = $body | ConvertFrom-Json | ConvertTo-Json -Compress -Depth 100
            $response = Invoke-RestMethod -Method $Method -Body $bodyJson -Uri $Uri -Headers $headers -ErrorAction Stop
        }Else{
            $response = Invoke-RestMethod -Method $Method -Uri $Uri -Headers $headers -ErrorAction Stop
        }
        Write-Host "Invoked ""$Method"" on URI`: $Uri"
        Write-Host "JSON Payload`: $bodyJson"
    }Catch{
        Write-Warning -Message $("Failed Invoking ""$Method"" on URI`: ""$Uri"". Error " + $_.Exception.Message)
        Return $Null;
    }
    Return $response;
}#'End Function Invoke-OntapRestCli.
#'------------------------------------------------------------------------------
#'Enumerate SnapMirror transfers.
#'------------------------------------------------------------------------------
[Int]$errorCount = 0
[String]$uri     = "https://$cluster/api/private/cli/snapmirror?fields=state,status&amp;amp;status=transferring"
Try{
    $transfers = Invoke-RestMethod -Uri $uri -Method Get -Credential $credential -ErrorAction Stop
    Write-Host "Enumerated SnapMirror Transfers for cluster ""$Cluster"" using URI ""$uri"""
}Catch{
    Write-Warning $("Failed Enumerating SnapMirror Transfers for cluster ""$Cluster"" using URI ""$uri"". Error " + $_.Exception.Message)
    Exit -1
}
#'------------------------------------------------------------------------------
# Iterate through each SnapMirror transfer and abort it.
#'------------------------------------------------------------------------------
If($Null -ne $transfers){
    ForEach($record In $transfers.records){
        [String]$source = $record.source_path
        [String]$target = $record.destination_path
        [String]$uri    = "https://$cluster/api/private/cli/snapmirror/abort"
        $snapmirror = @{
           "source-path"      = $source;
           "destination-path" = $target
        }
        $body = $snapmirror | ConvertTo-Json
        Try{
            $response = Invoke-OntapRestCli -Cluster $Cluster -Uri $uri -Method Post -Body $body -Credential $credential -ErrorAction Stop
            Write-Host "Successfully aborted SnapMirror using URI`: $uri"
        }Catch{
            Write-Warning -Message $("Failed aborting SnapMirror Transfer using URI`: $uri. Error " + $_.Exception.Message)
            [Int]$errorCount++
        }
        Write-Host $response
    }
}Else{
    Write-Host "There are no snapmirror transfers on cluster ""$cluster"""
}
If($errorCount -eq 0){
   Write-Host "Completed Successfully"
}Else{
   Write-Host "Completed with $errorCount Errors"
}
#'------------------------------------------------------------------------------&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Syntax:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;PS C:\Scripts\PowerShell\Projects\AbortSnapMirrorTransfers&amp;gt; $credentials = Get-Credential -Credential admin
PS C:\Scripts\PowerShell\Projects\AbortSnapMirrorTransfers&amp;gt; .\AbortSnapMirrorTransfers.ps1 -Cluster 192.168.100.3 -Credential $credentials
Enumerated SnapMirror Transfers for cluster "192.168.100.3" using URI "https://192.168.100.3/api/private/cli/snapmirror?fields=state,status&amp;amp;status=transferring"
Invoked "Post" on URI: https://192.168.100.3/api/private/cli/snapmirror/abort
JSON Payload: {"source-path":"vserver1:","destination-path":"vserver1_dr:"}
Successfully aborted SnapMirror using URI: https://192.168.100.3/api/private/cli/snapmirror/abort
Completed Successfully&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/Matt&lt;/P&gt;</description>
    <pubDate>Fri, 07 Jun 2024 12:19:16 GMT</pubDate>
    <dc:creator>mbeattie</dc:creator>
    <dc:date>2024-06-07T12:19:16Z</dc:date>
    <item>
      <title>dataontap module - using powershell to invoke abort on all active snapmirror sessions</title>
      <link>https://community.netapp.com/t5/ONTAP-Discussions/dataontap-module-using-powershell-to-invoke-abort-on-all-active-snapmirror/m-p/452556#M43603</link>
      <description>&lt;P&gt;I have&amp;nbsp; a script that can quiesce or abort on a single relationship&amp;nbsp; (Invoke-NcSnapmirrorAbort...or Quiesce)&lt;/P&gt;&lt;P&gt;My goal is to have&amp;nbsp; is to Invoke_ .... Abort on all volumes (active replication sessions).&amp;nbsp; Can I supply a global value&amp;nbsp; to&amp;nbsp; DESTINATION to acccomplish this...or do i have to run the abort against each relationship?&amp;nbsp; Or how? thanks&lt;/P&gt;&lt;P&gt;We want to automate a "kill" for all active sessions!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Heres the command syntax for abort ..hope you can read it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="thaddad_1-1715017083312.png" style="width: 786px;"&gt;&lt;img src="https://community.netapp.com/t5/image/serverpage/image-id/28211i85363114B2F6E0C3/image-dimensions/786x56?v=v2" width="786" height="56" role="button" title="thaddad_1-1715017083312.png" alt="thaddad_1-1715017083312.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2024 17:46:20 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Discussions/dataontap-module-using-powershell-to-invoke-abort-on-all-active-snapmirror/m-p/452556#M43603</guid>
      <dc:creator>thaddad</dc:creator>
      <dc:date>2024-05-06T17:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: dataontap module - using powershell to invoke abort on all active snapmirror sessions</title>
      <link>https://community.netapp.com/t5/ONTAP-Discussions/dataontap-module-using-powershell-to-invoke-abort-on-all-active-snapmirror/m-p/453121#M43673</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's a script that using the private REST CLI to enumerate all snapmirror relationships that are in a transferring state and abort them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Param(
    [Parameter(Mandatory = $True, HelpMessage="The Destination Cluster name or IP Address")]
    [String]$Cluster,
    [Parameter(Mandatory = $False, HelpMessage = "The Credentials to authenticate to ONTAP")]
    [System.Management.Automation.PSCredential]$Credential
)
#'------------------------------------------------------------------------------
Function Get-OntapAuthorization{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory = $True, HelpMessage = "The Credential to authenticate to the ONTAP 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-OntapAuthorization.
#'------------------------------------------------------------------------------
Function Invoke-OntapRestCli{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory = $True, HelpMessage = "The Cluster Name or IP Address")]
        [String]$Cluster,
        [Parameter(Mandatory = $True, HelpMessage = "The REST API Method to Invoke")]
        [ValidateSet("get","patch","post","delete")]
        [String]$Method,
        [Parameter(Mandatory = $False, HelpMessage = "The JSON payload used for creating or modifying an object")]
        [String]$Body,
        [Parameter(Mandatory = $True, HelpMessage = "The URI to invoke")]
        [String]$Uri,
        [Parameter(Mandatory = $True, HelpMessage = "The Credential to authenticate to the Cluster")]
        [ValidateNotNullOrEmpty()]
        [System.Management.Automation.PSCredential]$Credential
    )
    #'--------------------------------------------------------------------------
    #'Exit if the body is not provided when calling the post or patch method.
    #'--------------------------------------------------------------------------
    If(($Method -eq "post" -Or $Method -eq "patch") -And ($Null -eq $Body)){
        Write-Warning -Message "The body parameter must be provided when invoking the patch or post method"
        Return $Null;
    }
    #'--------------------------------------------------------------------------
    #'Add the CLI privilege Level to the command and set the Authentication header.
    #'--------------------------------------------------------------------------
    $headers = Get-OntapAuthorization -Credential $Credential
    #'--------------------------------------------------------------------------
    #'Invoke the command via the private REST CLI.
    #'--------------------------------------------------------------------------
    Try{
        If($Method -eq "post" -Or $Method -eq "patch"){
            $bodyJson = $body | ConvertFrom-Json | ConvertTo-Json -Compress -Depth 100
            $response = Invoke-RestMethod -Method $Method -Body $bodyJson -Uri $Uri -Headers $headers -ErrorAction Stop
        }Else{
            $response = Invoke-RestMethod -Method $Method -Uri $Uri -Headers $headers -ErrorAction Stop
        }
        Write-Host "Invoked ""$Method"" on URI`: $Uri"
        Write-Host "JSON Payload`: $bodyJson"
    }Catch{
        Write-Warning -Message $("Failed Invoking ""$Method"" on URI`: ""$Uri"". Error " + $_.Exception.Message)
        Return $Null;
    }
    Return $response;
}#'End Function Invoke-OntapRestCli.
#'------------------------------------------------------------------------------
#'Enumerate SnapMirror transfers.
#'------------------------------------------------------------------------------
[Int]$errorCount = 0
[String]$uri     = "https://$cluster/api/private/cli/snapmirror?fields=state,status&amp;amp;status=transferring"
Try{
    $transfers = Invoke-RestMethod -Uri $uri -Method Get -Credential $credential -ErrorAction Stop
    Write-Host "Enumerated SnapMirror Transfers for cluster ""$Cluster"" using URI ""$uri"""
}Catch{
    Write-Warning $("Failed Enumerating SnapMirror Transfers for cluster ""$Cluster"" using URI ""$uri"". Error " + $_.Exception.Message)
    Exit -1
}
#'------------------------------------------------------------------------------
# Iterate through each SnapMirror transfer and abort it.
#'------------------------------------------------------------------------------
If($Null -ne $transfers){
    ForEach($record In $transfers.records){
        [String]$source = $record.source_path
        [String]$target = $record.destination_path
        [String]$uri    = "https://$cluster/api/private/cli/snapmirror/abort"
        $snapmirror = @{
           "source-path"      = $source;
           "destination-path" = $target
        }
        $body = $snapmirror | ConvertTo-Json
        Try{
            $response = Invoke-OntapRestCli -Cluster $Cluster -Uri $uri -Method Post -Body $body -Credential $credential -ErrorAction Stop
            Write-Host "Successfully aborted SnapMirror using URI`: $uri"
        }Catch{
            Write-Warning -Message $("Failed aborting SnapMirror Transfer using URI`: $uri. Error " + $_.Exception.Message)
            [Int]$errorCount++
        }
        Write-Host $response
    }
}Else{
    Write-Host "There are no snapmirror transfers on cluster ""$cluster"""
}
If($errorCount -eq 0){
   Write-Host "Completed Successfully"
}Else{
   Write-Host "Completed with $errorCount Errors"
}
#'------------------------------------------------------------------------------&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Syntax:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;PS C:\Scripts\PowerShell\Projects\AbortSnapMirrorTransfers&amp;gt; $credentials = Get-Credential -Credential admin
PS C:\Scripts\PowerShell\Projects\AbortSnapMirrorTransfers&amp;gt; .\AbortSnapMirrorTransfers.ps1 -Cluster 192.168.100.3 -Credential $credentials
Enumerated SnapMirror Transfers for cluster "192.168.100.3" using URI "https://192.168.100.3/api/private/cli/snapmirror?fields=state,status&amp;amp;status=transferring"
Invoked "Post" on URI: https://192.168.100.3/api/private/cli/snapmirror/abort
JSON Payload: {"source-path":"vserver1:","destination-path":"vserver1_dr:"}
Successfully aborted SnapMirror using URI: https://192.168.100.3/api/private/cli/snapmirror/abort
Completed Successfully&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/Matt&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2024 12:19:16 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Discussions/dataontap-module-using-powershell-to-invoke-abort-on-all-active-snapmirror/m-p/453121#M43673</guid>
      <dc:creator>mbeattie</dc:creator>
      <dc:date>2024-06-07T12:19:16Z</dc:date>
    </item>
    <item>
      <title>Re: dataontap module - using powershell to invoke abort on all active snapmirror sessions</title>
      <link>https://community.netapp.com/t5/ONTAP-Discussions/dataontap-module-using-powershell-to-invoke-abort-on-all-active-snapmirror/m-p/457048#M44329</link>
      <description>&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stops ongoing transfers for a SnapMirror relationship.&lt;/P&gt;&lt;P&gt;C:\PS&amp;gt;Invoke-NcSnapmirrorAbort VxeRubble://costea02/unitTestLunsSM&lt;/P&gt;&lt;P&gt;Abort any SnapMirror transfers to destination 'VxeRubble://costea02/unitTestLunsSM'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Disables future transfers to a SnapMirror destination.&lt;/P&gt;&lt;P&gt;C:\PS&amp;gt;Invoke-NcSnapmirrorQuiesce //costea02/unitTestLunsSM -Passthru&lt;/P&gt;&lt;P&gt;Quiesce the SnapMirror with destination '//costea02/unitTestLunsSM' and display the SnapMirror object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SourceLocation DestinationLocation Status MirrorState&lt;BR /&gt;-------------- ------------------- ------ -----------&lt;BR /&gt;VxeRubble://costea01/unitTestLuns VxeRubble://costea02/unitTestLunsSM quiesced snapmirrored&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;C:\PS&amp;gt;$q = Get-NcSnapmirror -Template&lt;BR /&gt;$q.SourceVserver = "beam01"&lt;BR /&gt;Invoke-NcSnapmirrorQuiesce -Query $q&lt;/P&gt;&lt;P&gt;Quiesce all snapmirror relationships for source vserver beam01.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SuccessCount : 1&lt;BR /&gt;FailureCount : 0&lt;BR /&gt;SuccessList : {beam01:luns --&amp;gt; beam02:luns}&lt;BR /&gt;FailureList : {}&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2024 02:40:04 GMT</pubDate>
      <guid>https://community.netapp.com/t5/ONTAP-Discussions/dataontap-module-using-powershell-to-invoke-abort-on-all-active-snapmirror/m-p/457048#M44329</guid>
      <dc:creator>Ashun</dc:creator>
      <dc:date>2024-12-04T02:40:04Z</dc:date>
    </item>
  </channel>
</rss>

