protections.psm1


$SchedulersDefaultProperties = ('name', 'index', 'sys-name', 'snapshot-type', 'scheduler-type', 'schedule', 'last-activation-status', 'suffix', 'enabled-state')
$ProtectionClustersDefaultProperties = ('cluster-list', 'sys-id', 'num-remote-replication-sessions', 'num-of-ip-links', 'sys-connectivity-state', 'system-active-status')

$ProtectionIPLinksDefaultProperties = ('name', 'link-rate', 'a-end-sys-id', 'a-end-ip-addr', 'z-end-sys-id', 'z-end-ip-addr', 'ip-link-state')
# $TestProtectionIPLinkDefaultProperties = ('pairing-label', 'state', 'link-rate', 'enabled-state', 'num-active-rep-sessions', 'num-configures-rep-sessions', 'consistency-state')
$ProtectionPortsDefaultProperties = ('sys-name', 'port-state', 'num-of-links', 'port-address')
$ProtectionVolumesDefaultProperties = ('name', 'vol-size', 'vol-access', 'naa-name', 'creation-time')
$ProtecitonConsistencyGroupsDefaultProperties = ('cg-name', 'num-of-snap-sets', 'num-of-vols', 'num-replication-sessions', 'guid')
$LocalProtectionSessionDefaultProperties = ('name', 'enabled-state', 'snapped-object-id', 'retention-policy-id', 'guid', 'index')
$RemoteProtetctionSessionDefaultProperties = ('index', 'name', 'replication-state', 'replication-mode', 'replication-direction', 'source-sys-id', 'target-sys-id', 'source-xms-id', 'target-xms-id', 'source-cg-id', 'target-cg-id', 'num-of-vols', 'guid')
# $ProtectionVolumePairsDefaultProperties = ('source-xms', 'source-cluster', 'source-volume-pair-id')
$LocalProtectionSnpashotSetDefaultProperties = ('name', 'session-name', 'cg-name', 'num-of-vols')
$RemoteProtectionSnpashotSetDefaultProperties = ('index', 'name', "sys-id", "rep-snapset-state", "test-copy-in-progress", "guid", 'creation-time-long')
$ProtectionRetentionPoliciesDefaultProperties = ('index', 'name', 'sys-id', 'num-references', 'protection-window-duration-in-days', 'protection-window-num-copies')

.(commonLib) 



Function Get-XtremRemoteProtectionPeerXMS {
    [cmdletbinding()]
    [Alias('xmsRemoteProtectionListPeerXMS')]
    Param (
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [parameter()]
        [Alias("Properties")]
        [array]$Property,
        [parameter()]
        [Alias("Filters")]
        [array]$Filter,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest,
        [Parameter()]
        [switch]$Full = $false
    )
    initCommand
    $Route = '/types/protection-domains'

    if ($Full) { $Property = '' }
    
    $result = NewXtremRequest -Method GET -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Properties $Property -Filters $Filter -ShowRest:$ShowRest.IsPresent -Multi -Full:$Full.IsPresent
    
    $result = formatOutPut $Property $result
    
    finalizeCommand
    return $result
}

Function New-XtremRemoteProtectionPeerXMS {
 <#
    .DESCRIPTION
    Add a Remote protection XMS
     
    .PARAMETER XMSName
     
    .PARAMETER IPAddress
     
    .PARAMETER XMSUser
 
    .PARAMETER XMSPassword
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    New-XtremRemoteProtectionPeerXMS -XMSName "NewXMS" -IPAddress "10.0.0.1" -XMSUser "username" -XMSPassword "password"
  #>

    [CmdletBinding()]
    [Alias('xmsRemoteProtectionAddPeerXMS')]
    Param (
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [String]$XMSName,
        [Parameter()]
        [String]$IPAddress,
        [Parameter()]
        [String]$XMSUser,
        [parameter()]
        [String]$XMSPassword,
        [parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/commands/xms/add-peer/'
    $BodyList = @{ }
    
    AddIfExists -name "remote-xms-alias-name" -value $XMSName -list $BodyList
    AddIfExists -name "remote-ip-addr" -value $IPAddress -list $BodyList
    AddIfExists -name "remote-xms-user" -value $XMSUser -list $BodyList
    AddIfExists -name "remote-user-password" -value $XMSPassword -list $BodyList
    
    $Body = BuildXtremJson -list $BodyList
    
    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -Body $Body -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function Set-XtremRemoteProtectionPeerXMS {
<#
    .DESCRIPTION
    Modify a Remote protection Peer XMS
     
    .PARAMETER XMSName
     
    .PARAMETER IPAddress
     
    .PARAMETER XMSUser
 
    .PARAMETER XMSPassword
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Set-XtremRemoteProtectionPeerXMS -XMSName "NewXMS" -NewXMSName "RenamedXMS"-IPAddress "10.0.0.1" -XMSUser "username" -XMSPassword "password"
  #>

    [CmdletBinding()]
    [Alias('xmsRemoteProtectionModifyPeerXMS')]
    Param (
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [String]$XMSName,
        [Parameter()]
        [String]$NewXMSName,
        [Parameter()]
        [String]$IPAddress,
        [Parameter()]
        [String]$XMSUser,
        [parameter()]
        [String]$XMSPassword,
        [parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/commands/xms/modify-peer/'
    $Route, $GetProperty = SetParametersForRequest $Route $XMSName
    
    $BodyList = @{ }
    
    AddIfExists -name "xms-alias-name" -value $XMSName -list $BodyList
    AddIfExists -name "new-xms-alias-name" -value $NewXMSName -list $BodyList
    AddIfExists -name "new-ip-addr" -value $IPAddress -list $BodyList
    
    $Body = BuildXtremJson -list $BodyList
    
    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $Body -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function Remove-XtremRemoteProtectionPeerXMS {
  <#
    .DESCRIPTION
    Removes a Remote Protection XMS Peer
     
    .PARAMETER Name
    name of the XMS
 
    .PARAMETER XMSUser
 
    .PARAMETER XMSPassword
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Remove-XtremRemoteProtectionPeerXMS -Name "XMS" -XMSUsername "username" -XMSPassword "password"
  #>

    [cmdletbinding()]
    [Alias('xmsRemoteProtectionRemovePeerXMS')]
    Param (
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Alias("Name", "Index")]
        [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        $XMSName,
        [Parameter()]
        [String]$XMSUser,
        [parameter()]
        [String]$XMSPassword,
        [Parameter()]
        [bool]$Force,
        [Parameter()]
        [bool]$Confirm =  (Get-XtremDefaultSession)._XtremCLIMode,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    $confirmed = IsConfirmed $Confirm
    if (!$confirmed) {
        return
    }
    initCommand
    $Route = '/commands/xms/remove-peer/'
    $Route, $GetProperty = SetParametersForRequest $Route $XMSName

    $BodyList = @{ }
    
    AddIfExists -name "force" -value $Force -list $BodyList
    AddIfExists -name "xms-alias-name" -value $XMSName -list $BodyList
    
    $Body = BuildXtremJson -list $BodyList

    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $Body -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function Get-XtremRemoteProtectionClusters {
  <#
    .DESCRIPTION
    Get remote protection clusters
 
    .PARAMETER Properties
    Array of properties requested from this call.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Get-XtremRemoteProtectionClusters
  #>

    [cmdletbinding()]
    [Alias('xmsRemoteProtectionListClusters')]
    Param (
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Alias("Name", "Index")]
        [Parameter()]
        [Alias("Properties")]
        [string[]]$Property=$ProtectionClustersDefaultProperties,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest,
        [parameter()]
        [Alias("Filters")]
        [array]$Filter,
        [Parameter()]
        [switch]$Full = $false
    )
    initCommand
    $Route = '/types/protection-domains'

    if ($Full) { $Property = '' }
    
    $result = NewXtremRequest -Method GET -Endpoint $Route -XtremClusterName $XtremClusterName -Session $Session -Properties $Property -ShowRest:$ShowRest.IsPresent -Multi -Full:$Full.IsPresent

    $result = formatOutPut $Property $result
    
    finalizeCommand
    return $result
}

Function Get-XtremRemoteProtectionIPLinks {
<#
    .DESCRIPTION
    Displays the list of all Protection IP Links.
 
    .PARAMETER Properties
    Array of properties requested from this call.
 
    .PARAMETER Filters
    Array of filters for this call.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
        Get-XtremRemoteProtectionIPLinks
  #>

    [cmdletbinding()]
    [Alias('xmsRemoteProtectionListIPLinks')]
    Param (
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [parameter()]
        [Alias("Properties")]
        [Argumentcompleter( { doComplete $args 'ip-links' prop })] 
        [array]$Property = $ProtectionIPLinksDefaultProperties,
        [parameter()]
        [Alias("Filters")]
        [Argumentcompleter( { doComplete $args 'ip-links' filter })] 
        [array]$Filter,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest,
        [Parameter()]
        [switch]$Full = $false
    )
    initCommand
    $Route = '/types/ip-links'

    if ($Full) { $Property = '' }
    
    $result = NewXtremRequest -Method GET -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Properties $Property -Filters $Filter -ShowRest:$ShowRest.IsPresent -Multi -Full:$Full.IsPresent
    
    $result = formatOutPut $Property $result
    
    finalizeCommand
    return $result
}

Function Get-XtremRemoteProtectionIpLink {
  <#
    .DESCRIPTION
    displays the details of Remote Protection Ip Link
 
    .PARAMETER IpLink
    The name/index or guid of an Ip link
 
    .PARAMETER Properties
    Array of properties requested from this call.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Get-XtremRemoteProtectionIpLink -IpLink name
  #>

    [cmdletbinding()]
    [Alias('xmsRemoteProtectionGetIPLink')]
    Param (
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Alias("Name", "Index")]
        [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'ip-links' name })] 
        $IpLink,
        [Parameter()]
        [Alias("Properties")]
        [Argumentcompleter( { doComplete $args 'ip-links' prop })] 
        [string[]]$Property,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/ip-links'
    $Route, $GetProperty = SetParametersForRequest $Route $IpLink
    
    $result = NewXtremRequest -Method GET -Endpoint $Route -XtremClusterName $XtremClusterName -Session $Session -GetProperty $GetProperty -Properties $Property -ShowRest:$ShowRest.IsPresent

    $result = formatOutPut $Property $result
    
    finalizeCommand
    return $result
}

Function New-XtremRemoteProtectionIpLink {
 <#
    .DESCRIPTION
    Adds one explicit IP link between two clusters.
     
    .PARAMETER IpLinkName
    Name of IP Link.
    .PARAMETER SourceXMSName
     
    .PARAMETER SourceClusterId
     
    .PARAMETER SourceIPAddrSN
 
    .PARAMETER TargetXMSName
 
    .PARAMETER TargetClusterID
 
    .PARAMETER TargetIPAddrSN
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    New-XtremRemoteProtectionIpLink - IpLinkName Test
  #>

    [CmdletBinding()]
    [Alias('xmsRemoteProtectionCreateIPLink')]
    Param (
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [ValidatePattern("^[^\[\]&\(\)`";,<>'/]+$")] 
        [String]$IpLinkName,
        [Parameter()]
        [String[]]$SourceXMSName,
        [Parameter()]
        $SourceClusterId,
        [parameter()]
        $SourceIPAddrSN,
        [Parameter()]
        $TargetXMSName,
        [Parameter()]
        $TargetClusterID,
        [Parameter()]
        $TargetIPAddrSN,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/ip-links'
    $BodyList = @{ }
    
    AddIfExists -name "ip-link-name" -value $IpLinkName -list $BodyList
    AddIfExists -name "source-xms-name" -value $SourceXMSName -list $BodyList
    AddIfExists -name "source-cluster-id" -value $SourceClusterId -list $BodyList
    AddIfExists -name "source-ip-addr-sn" -value $SourceIPAddrSN -list $BodyList
    AddIfExists -name "target-xms-name" -value $TargetXMSName -list $BodyList
    AddIfExists -name "target-cluster-id" -value $TargetClusterID -list $BodyList
    AddIfExists -name "target-ip-addr-sn" -value $TargetIPAddrSN -list $BodyList
    
    $Body = BuildXtremJson -list $BodyList
        
    $result = NewXtremRequest -Method POST -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $Body -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}


Function Set-XtremRemoteProtectionIpLink {
 <#
    .DESCRIPTION
    Modifies an IP Link.
     
    .PARAMETER IpLinkName
    IP Link index or name
 
    .PARAMETER IpLinkId
    IP Link index or name
 
    .PARAMETER Enable
    This property indicates if the port is currently enabled or has been disabled either by the user or by the system.
 
    .PARAMETER Disable
    This property indicates if the port is currently enabled or has been disabled either by the user or by the system.
 
    .PARAMETER RefreshLinkCredntials
     
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Set-XtremRemoteProtectionIpLink -IpLinkName test -Enabled $True
  #>

    [CmdletBinding()]
    [Alias('xmsRemoteProtectionModifyIPLink')]
    Param (
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Alias("Name", "Index")]
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'ip-links' name })] 
        $IpLinkName,
        [parameter()]
        $IPLinkId,
        [parameter()]
        [bool]$Enable,
        [parameter()]
        [bool]$Disable,
        [parameter()]
        $RefreshLinkCredntials,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/ip-links'
    $Route, $GetProperty = SetParametersForRequest $Route $IpLinkName
    
    $BodyList = @{ }
    
    
    AddIfExists -name "ip-link-id" -value $IPLinkId -list $BodyList
    AddIfExists -name "ip-link-name" -value $IPLinkName -list $BodyList
    AddIfExists -name "enable" -value $Enable -list $BodyList
    AddIfExists -name "disable" -value $Disable -list $BodyList
    AddIfExists -name "refresh-link-credentials" -value $RefreshLinkCredentials -list $BodyList
    
    $Body = BuildXtremJson -list $BodyList
    
    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $Body -GetProperty $GetProperty -ShowRest:$ShowRest.IsPresent
    
    finalizeCommand
    return $result
}

Function Remove-XtremRemoteProtectionIpLink {
  <#
    .DESCRIPTION
    Removes on specified IP Link between two clusters
     
    .PARAMETER Name
    current name or index number of IP Link
 
    .PARAMETER Force
    Default value is False. Allows invoking a one-sided removal incase of no-connectivity to the peer XMS.
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Remove-XtremRemoteProtectionIpLink -IPLinkName test
  #>

    [cmdletbinding()]
    [Alias('xmsRemoteProtectionRemoveIPLink')]
    Param (
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Alias("Name", "Index")]
        [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'ip-links' name })] 
        $IPLinkName,
        [Parameter()]
        [bool]$Force,
        [Parameter()]
        [bool]$Confirm =  (Get-XtremDefaultSession)._XtremCLIMode,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    
    $confirmed = IsConfirmed $Confirm
    if (!$confirmed)
    {
        return
    }
    initCommand
    $Route = '/types/ip-links'
    $Route, $GetProperty = SetParametersForRequest $Route $Name
    
    $BodyList = @{ }
    
    # AddIfExists -name "force" -value $Force -list $BodyList
    
    $result = NewXtremRequest -Method DELETE -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $BodyList -GetProperty $GetProperty -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function Get-XtremRemoteProtectionPorts {
  <#
    .DESCRIPTION
    Lists all replication ports related to specified cluster
 
    .PARAMETER XtremClisterName
    Cluster Object Id
     
    .PARAMETER XmsName
    Name of the XMS
 
    .PARAMETER Properties
    Array of properties requested from this call.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Get-XtremRemoteProtectionPorts
  #>

    [cmdletbinding()]
    [Alias('xmsRemoteProtectionListPorts')]
    Param (
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Alias("Name", "Index")]
        [parameter()]
        [string]$XMSName,
        [Parameter()]
        [Alias("Properties")]
        [string[]]$Property = $ProtectionPortsDefaultProperties,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/r-target-ports'
    
    $BodyList = @{ }
    AddIfExists -name "xms-name" -value $Force -list $BodyList
    
    $result = NewXtremRequest -Method GET -Endpoint $Route -XtremClusterName $XtremClusterName -Session $Session -Body $BodyList -Properties $Property -ShowRest:$ShowRest.IsPresent
    
    $result = formatOutPut $Property $result
    
    finalizeCommand
    return $result
}

Function Get-XtremRemoteProtectionVolumes {
  <#
    .DESCRIPTION
    Lists the volumes and thier details for a specifed XMS and cluster.
 
    .PARAMETER XtremClisterName
    Cluster Object Id
     
    .PARAMETER XmsName
    Name of the XMS
 
    .PARAMETER Properties
    Array of properties requested from this call.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Get-XtremRemoteProtectionVolumes
  #>

    [cmdletbinding()]
    [Alias('xmsRemoteProtectionListVolumes')]
    Param (
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Alias("Name", "Index")]
        [parameter()]
        [string]$XMSName,
        [Parameter()]
        [Alias("Properties")]
        [string[]]$Property = $ProtectionVolumesDefaultProperties,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/r-volumes'
    
    $BodyList = @{ }
    AddIfExists -name "xms-name" -value $Force -list $BodyList
    
    $result = NewXtremRequest -Method GET -Endpoint $Route -XtremClusterName $XtremClusterName -Session $Session -Body $BodyList -Properties $Property -ShowRest:$ShowRest.IsPresent
    
    $result = formatOutPut $Property $result
    
    finalizeCommand
    return $result
    
}

Function Get-XtremRemoteProtectionConsistencyGroups {
  <#
    .DESCRIPTION
    Lists CGs that are under remote protection, active or not.
 
    .PARAMETER XtremClisterName
    Cluster Object Id
     
    .PARAMETER XmsName
    Name of the XMS
 
    .PARAMETER Properties
    Array of properties requested from this call.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Get-XtremRemoteProtectionConsistencyGroups
  #>

    [cmdletbinding()]
    [Alias('xmsRemoteProtectionConsistencyGroups')]
    Param (
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Alias("Name", "Index")]
        [parameter()]
        [string]$XMSName,
        [Parameter()]
        [Alias("Properties")]
        [string[]]$Property = $ProtecitonConsistencyGroupsDefaultProperties,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/r-consistency-groups'
    
    $BodyList = @{ }
    AddIfExists -name "xms-name" -value $Force -list $BodyList
    
    $result = NewXtremRequest -Method GET -Endpoint $Route -XtremClusterName $XtremClusterName -Session $Session -Body $BodyList -Properties $Property -ShowRest:$ShowRest.IsPresent
    
    $result = formatOutPut $Property $result
    
    finalizeCommand
    return $result
}

Function Get-XtremLocalProtectionSessions {
  <#
    .DESCRIPTION
    Show local protection sessions.
 
    .PARAMETER XtremClisterName
    Cluster Object Id
     
    .PARAMETER Properties
    Array of properties requested from this call.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Get-XtremLocalProtectionSessions
  #>

    [cmdletbinding()]
    [Alias('xmsLocalProtectionList')]
    Param (
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Alias("Name", "Index")]
        [Parameter()]
        [Alias("Properties")]
        [string[]]$Property = $LocalProtectionSessionDefaultProperties,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/local-protections'
    
    $result = NewXtremRequest -Method GET -Endpoint $Route -XtremClusterName $XtremClusterName -Session $Session -Properties $Property -ShowRest:$ShowRest.IsPresent

    $result = formatOutPut $Property $result
    
    finalizeCommand
    return $result
}

Function Get-XtremRemoteProtectionSession {
  <#
    .DESCRIPTION
    Get a remote protection session by Id/Guid.
     
    .PARAMETER ProtectionSessionId
    ID or Name of the remote protection session
 
    .PARAMETER Properties
      Array of properties requested from this call.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Get-XtremLocalProtectionSession 2 -prop name,replication-state
  #>

    [cmdletbinding()]
    [Alias('xmsRemoteProtectionGet')]
    Param (
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'remote-protections' name })] 
        $ProtectionSessionId,
        [Parameter()]
        [Alias("Properties")]
        [Argumentcompleter( { doComplete $args 'remote-protections' prop })] 
        [array]$Property,
        [object]$Session =  (Get-XtremDefaultSession),
        [parameter()]                                    
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = "/types/remote-protections"

    $Route, $GetProperty = SetParametersForRequest $Route $ProtectionSessionId

    $result = NewXtremRequest -Method GET -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Properties $Property -GetProperty $GetProperty -ShowRest:$ShowRest.IsPresent

    $result = formatOutPut $Property $result
    
    finalizeCommand
    return $result
}


Function Get-XtremRemoteProtectionSessions {
  <#
    .DESCRIPTION
    Show remote protection sessions.
     
    .PARAMETER Properties
    Array of properties requested from this call.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Get-XtremRemoteProtectionSessions
  #>

    [cmdletbinding()]
    [Alias('xmsRemoteProtectionList')]
    Param (
        [Parameter()]
        [Alias("Properties")]
        [Argumentcompleter( { doComplete $args 'remote-protections' prop })] 
        [string[]]$Property = $RemoteProtetctionSessionDefaultProperties,
        [parameter()]
        [Alias("Filters")]
        [Argumentcompleter( { doComplete $args 'remote-protections' filter })] 
        [array]$Filter,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [parameter()]                                    
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/remote-protections/'

    $result = NewXtremRequest -Method GET -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Filters $Filter -Properties $Property -ShowRest:$ShowRest.IsPresent

    $result = formatOutPut $Property $result
    
    finalizeCommand
    return $result
}

Function New-XtremLocalProtectionSession {
 <#
    .DESCRIPTION
    Adds Locall Protection Session to a cluster.
     
    .PARAMETER LocalProtectionId
    Name of protection session.
 
    .PARAMETER SnappedObjectId
    The ID of the snapped object to be protected locally.
 
    .PARAMETER SnappedObjectType
    The Type of the snapped object to be protected locally (Volume or CG only).
 
    .PARAMETER schedule
    For local protection the client can be either rpo or schedule. Rpo is the only option allowed for remote protection only.
 
    .PARAMETER RetentionPolicyId
    Retention policy is optional. If no policy id is specified, then only the current cycle and the last cycle PITs are retained.
     
    .PARAMETER Suffix
        Specifies the suffix to be used for the volume (snapshots) being created. Local protection only.
 
    .PARAMETER EnabledState
 
    .PARAMETER SnapshotType
    Determines whether the snapshots created by local protection are writable or readonly. Possible values: regular, readonly
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    New-XtremLocalProtectionSession -LocalProtectionId test
  #>

    [CmdletBinding()]
    [Alias('xmsLocalProtectionCreate')]
    Param (
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'local-protections' name })]
        [ValidatePattern("^[^\[\]&\(\)`";,<>'/]+$")] 
        [String]$LocalProtectionId,
        [Parameter()]
        $SnappedObjectId,
        [Parameter()]
        [ValidateSet('Volume', 'ConsistencyGroup')]
        $SnappedObjectType,
        [parameter()]
        $schedule,
        [Parameter()]
        $RetentionPolicyId,
        [Parameter()]
        $Suffix,
        [Parameter()]
        [ValidateSet('interval', 'explicit')]
        $EnabledState,
        [Parameter()]
        [ValidateSet('enabled', 'user_disabled','system_disabled')]
        $SnapshotType,
        [Parameter()]
        [object]$Session = (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/local-protections'
    
    $BodyList = @{ }
    
    AddIfExists -name "protection-session-name" -value $LocalProtectionId -list $BodyList
    AddIfExists -name "cluster-id" -value $XtremClusterName -list $BodyList
    AddIfExists -name "snapped-object-id" -value $SnappedObjectId -list $BodyList
    AddIfExists -name "snapped-object-type" -value $SnappedObjectType -list $BodyList
    AddIfExists -name "schedule" -value $schedule -list $BodyList
    AddIfExists -name "retention-policy-id" -value $RetentionPolicyId -list $BodyList
    AddIfExists -name "local-protection-type" -value $SnapshotType -list $BodyList
    AddIfExists -name "suffix" -value $Suffix -list $BodyList
    AddIfExists -name "enabled-state" -value $EnabledState -list $BodyList
    
    $Body = BuildXtremJson -list $BodyList
    
    $result = NewXtremRequest -Method POST -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $Body -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function New-XtremRemoteProtectionSession {
 <#
    .DESCRIPTION
    Adds Remote Protection Session
     
    .PARAMETER ProtectionSessionName
    Name of the created session.
 
    .PARAMETER SourceXMSName
    For remote protection only
 
    .PARAMETER SourceSysId
 
    .PARAMETER TargetXMSName
 
    .PARAMETER TargetSysId
 
    .PARAMETER SourceCGId
    By specifying the source cg-id, XMS can then calculated the replication direction.
     
    .PARAMETER TargetCGId
    By specifying the target cg-id, XMS can then calculate the replication direction.
     
    .PARAMETER AutoProvisionTarget
    Remote protection only. When true CG and volumes are created on the target cluster
 
    .PARAMETER RpoSec
     
    .PARAMETER TargetRetentionPolicyId
     
    .PARAMETER DefaultRetentionPolicyId
     
    .PARAMETER StartOnCreation
     
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
    .PARAMETER Mode
    Sync/async mode of replication session.
 
    .PARAMETER Suffix
    Specifies the suffix to be used for the volumes in case of auto provisioning.
 
    .EXAMPLE
    New-XtremRemoteProtectionSession psSess1 -TargetClusterId Cluster2 -SourceCGId CG_1 -AutoProvisionTarget -Mode sync
  #>

    [CmdletBinding()]
    [Alias('xmsRemoteProtectionCreate')]
    Param (
        [Parameter(ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'remote-protections' name })]
        [ValidatePattern("^[^\[\]&\(\)`";,<>'/]+$")]
        $ProtectionSessionName,
        [Parameter()]
        [Argumentcompleter( { fillFunc 'completeClusterName' $args })] 
        $TargetClusterId,
        [Parameter()]
        [Argumentcompleter( { doComplete $args 'consistency-groups' name })] 
        $SourceCGId,
        [Parameter(ParameterSetName = 'autoProvision')]
        [switch]$AutoProvisionTarget,
        [Parameter(ParameterSetName = 'CGselection')]
        [Argumentcompleter( { doComplete $args 'consistency-groups' name 'TargetClusterId' })] 
        $TargetCGId,
        [Parameter()]
        [ValidateSet("sync", "async")]
        $Mode,
        [Parameter()]
        $RpoSec,
        [Parameter()]
        [Argumentcompleter( { doComplete $args 'retention-policies' name 'TargetClusterId' })] 
        $TargetRetentionPolicyId,
        [Parameter()] 
        [Argumentcompleter( { doComplete $args 'retention-policies' name })] 
        $SourceRetentionPolicyId,
        [Parameter()]
        [switch]$StartOnCreation,
        [Parameter()]
        [ValidateSet('enabled', 'disabled')]
        $ProtectionWindowComplianceAlert,
        [Parameter()]
        [Argumentcompleter( { fillFunc 'completeClusterName' $args })] 
        $SourceClusterId = (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter()]
        $SourceXMSName,
        [parameter()]
        $TargetXMSName,
        [Parameter()]
        [switch]$ShowRest,
        [Parameter()]
        $Suffix
    )
    initCommand
    $Route = '/types/remote-protections'
    
    $BodyList = @{ }
    
    AddIfExists -name "protection-session-name" -value $ProtectionSessionName -list $BodyList
    AddIfExists -name "source-xms-name" -value $SourceXMSName -list $BodyList
    AddIfExists -name "source-cluster-id" -value $SourceClusterId -list $BodyList
    AddIfExists -name "source-consistency-group-id" -value $SourceCGId -list $BodyList
    
    AddIfExists -name "target-xms-name" -value $TargetXMSName -list $BodyList
    AddIfExists -name "target-cluster-id" -value $TargetClusterId -list $BodyList
    AddIfExists -name "target-consistency-group-id" -value $TargetCGId -list $BodyList
    
    
    AddIfExists -name "target-retention-policy-id" -value $TargetRetentionPolicyId -list $BodyList
    AddIfExists -name "source-retention-policy-id" -value $SourceRetentionPolicyId -list $BodyList
    
    AddIfExists -name "auto-provision-target" -value $AutoProvisionTarget.IsPresent -list $BodyList
    AddIfExists -name "missing_pits_alerts" -value $MissingPitsAlerts -list $BodyList
    AddIfExists -name "target-volume-access" -value $BlockAccessType -list $BodyList
    AddIfExists -name "start-on-creation" -value $StartOnCreation.IsPresent -list $BodyList
    AddIfExists -name "protection-widnow-compliance-alert" -value $VerificationEnabledState -list $BodyList

    if($AutoProvisionTarget){
        AddIfExists -name "auto-provision-target-suffix" -value $Suffix -list $BodyList
    }else{
        # volume-pairs-list: [["e679c875626f4e74a379adce9e262551", "f0bcd54d981345d4b87b54d8d3b9e942"]]
        $volsOfCGs = ((Get-XtremConsistencyGroupVolume $SourceCGId) | sort name).guid
        $volsOfCGt = ((Get-XtremConsistencyGroupVolume $TargetCGId -XtremClusterName $TargetClusterId -Session (getSessionByClusterName $TargetClusterId)) | sort name).guid
        $volPairs = [System.Collections.ArrayList]@()
        if($volsOfCGs -is [array]){
            for ($i = 0; $i -lt $volsOfCGs.Count; $i++) {
                $pair = @($volsOfCGs[$i], $volsOfCGt[$i])
                [void]$volPairs.Add($pair)
            }
        }else{
            $pair = @($volsOfCGs, $volsOfCGt)
            [void]$volPairs.Add($pair)
        }
        AddIfExists -name "volume-pairs-list" -value $volPairs -list $BodyList
    }

    $versionIsGreaterOrEqual6_3_0 = (($Session._XMSversion[0] + $Session._XMSversion[1]) -ge 63)
    if ( $versionIsGreaterOrEqual6_3_0 ){
        AddIfExists -name "protection-mode" -value $Mode -list $BodyList
        if ($Mode -eq "sync"){
            if ($RpoSec) {
                $RpoSec = $null
            }
        }
    }
    AddIfExists -name "rpo" -value $RpoSec -list $BodyList
    
    $Body = BuildXtremJson -list $BodyList
    
    $result = NewXtremRequest -Method POST -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $Body -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}


Function Set-XtremRemoteProtectionSession {
 <#
    .DESCRIPTION
    Modify properties of the specified remote-protection session.
     
    .PARAMETER ProtectionSessionId
 
    .PARAMETER NewProtectionSessionId
 
    .PARAMETER SourceRetentionPolicyId
     
    .PARAMETER RemoveSourceRetentionPolicy
 
    .PARAMETER TargetRetentionPolicyId
     
    .PARAMETER RemoveTargetRetentionPolicy
 
    .PARAMETER BlockAccessType
     
    .PARAMETER Rpo
 
    .PARAMETER UpdateCGVolumesAccess
 
    .PARAMETER Direction
     
    .PARAMETER Mode
    Sync/async mode of replication session
     
    .PARAMETER ProtectionWindowComplianceAlert
 
    .PARAMETER ReleaseLock
     
    .PARAMETER Force
 
     
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Set-XtremRemoteProtectionSession -Name test
  #>

    [CmdletBinding()]
    [Alias('xmsRemoteProtectionModify')]
    Param (
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter(ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'remote-protections' name })] 
        $ProtectionSessionId,
        [Parameter()]
        [ValidatePattern("^[^\[\]&\(\)`";,<>'/]+$")] 
        $NewProtectionSessionId,
        [Parameter()]
        $SourceRetentionPolicyId,
        [Parameter()]
        $RemoveSourceRetentionPolicy,
        [Parameter()]
        $TargetRetentionPolicyId,
        [Parameter()]
        $RemoveTargetRetentionPolicy,
        [Parameter()]
        $BlockAccessType,
        [Parameter()]
        $Rpo,
        [Parameter()]
        $UpdateCGVolumesAccess,
        [Parameter()]
        $Direction,
        [Parameter()]
        [ValidateSet('sync', 'async')]
        $Mode,
        [Parameter()]
        [ValidateSet('enabled', 'disabled')]
        $ProtectionWindowComplianceAlert,
        [Parameter()]
        $ReleaseLock,
        [Parameter()]
        [bool]$Force,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/remote-protections'
    
    $BodyList = @{ }
    $Route, $GetProperty = SetParametersForRequest $Route $ProtectionSessionId
    
    AddIfExists -name "new-protection-session-name" -value $NewProtectionSessionId -list $BodyList
    AddIfExists -name "source-retention-policy-id" -value $SourceRetentionPolicyId -list $BodyList
    AddIfExists -name "target-retention-policy-id" -value $TargetRetentionPolicyId -list $BodyList
    AddIfExists -name "remove-source-retention-policy-id" -value $RemoveSourceRetentionPolicyId -list $BodyList
    AddIfExists -name "remove-target-retention-policy-id" -value $RemoveTargetRetentionPolicyId -list $BodyList
    AddIfExists -name "target-volume-access" -value $BlockAccessType -list $BodyList
    AddIfExists -name "update-cg-volumes-access" -value $UpdateCGVolumesAccess -list $BodyList
    AddIfExists -name "direction" -value $Direction -list $BodyList
    AddIfExists -name "protection-window-compliance-alert" -value $ProtectionWindowComplianceAlert -list $BodyList
    AddIfExists -name "release_lock" -value $ReleaseLock -list $BodyList
    AddIfExists -name "force" -value $Force -list $BodyList

    $versionIsGreaterOrEqual6_3_0 = (($Session._XMSversion[0] + $Session._XMSversion[1]) -ge 63)
    if ( $versionIsGreaterOrEqual6_3_0 ) {
        AddIfExists -name "protection-mode" -value $Mode -list $BodyList
        if ($Mode -eq "sync") {
            if ($Rpo) {
                $Rpo = $null
            }
        }
        
    }
    AddIfExists -name "rpo" -value $Rpo -list $BodyList
    
    $Body = BuildXtremJson -list $BodyList
    
    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $Body -GetProperty $GetProperty -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function Start-XtremRemoteProtectionSession {
 <#
    .DESCRIPTION
    Starts the specified remote protection session by ID.
     
    .PARAMETER ProtectionSessionId
    ID or GUID of the remote protection session
         
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Start-XtremRemoteProtectionSession -ProtectionSessionId 1
  #>

    [CmdletBinding()]
    [Alias('xmsRemoteProtectionStart')]
    Param (
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter(Mandatory = $true,  ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'remote-protections' name })] 
        [string]$ProtectionSessionId,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    $state = getRemoteProtectionState($ProtectionSessionId)
    if ($state -ne 'inactive') {
        Write-Host "Session state is [$state] cannot call $($MyInvocation.MyCommand)" -ForegroundColor Red
        return
    }
    initCommand
    $Route = '/commands/remote-protections/start/'
    
    $Route, $GetProperty = SetParametersForRequest $Route $ProtectionSessionId

    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -GetProperty $GetProperty -XtremClusterName $XtremClusterName  -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function Suspend-XtremRemoteProtectionSession {
 <#
    .DESCRIPTION
    Suspends the specified remote protection session by ID.
     
    .PARAMETER ProtectionSessionId
    ID or GUID of the remote protection session
 
    .PARAMETER SuspendType
    Type: immediate or graceful
         
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Suspend-XtremRemoteProtectionSession -ProtectionSessionId 1 -suspendType immediate
  #>

    [CmdletBinding()]
    [Alias('xmsRemoteProtectionSuspend')]
    Param (
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'remote-protections' name })] 
        $ProtectionSessionId,
        [Parameter()]
        [ValidateSet('immediate', 'graceful')]
        $SuspendType = 'graceful',
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    $state = getRemoteProtectionState($ProtectionSessionId)
    if ($state -ne 'active') {
        Write-Host "Session state is [$state] cannot call $($MyInvocation.MyCommand)" -ForegroundColor Red
        return
    }
    initCommand
    
    $Route = '/commands/remote-protections/suspend/'
    
    $Route, $GetProperty = SetParametersForRequest $Route $ProtectionSessionId

    $BodyList = @{ }
    AddIfExists -name "suspend-type" -value $SuspendType -list $BodyList
    $Body = BuildXtremJson -list $BodyList

    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -Body $Body -GetProperty $GetProperty -XtremClusterName $XtremClusterName  -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function Terminate-XtremRemoteProtectionSession {
 <#
    .DESCRIPTION
    Terminates the specified remote protection session by ID.
     
    .PARAMETER ProtectionSessionId
    ID or GUID of the remote protection session
 
    .PARAMETER Force
     
         
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Terminate-XtremRemoteProtectionSession -ProtectionSessionId 1 -Force
  #>

    [CmdletBinding()]
    [Alias('xmsRemoteProtectionTerminate')]
    Param (
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'remote-protections' name })] 
        $ProtectionSessionId,
        [Parameter()]
        [switch]$Force,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $state = getRemoteProtectionState($ProtectionSessionId)
    if (($state -ne 'active') -and ($state -ne 'suspended') -and ($state -ne 'synchronized')) {
        Write-Host "Session state is [$state] cannot call $($MyInvocation.MyCommand)" -ForegroundColor Red
        return
    }
    
    $Route = '/commands/remote-protections/terminate/'
    
    $Route, $GetProperty = SetParametersForRequest $Route $ProtectionSessionId

    $BodyList = @{ }
    AddIfExists -name "force" -value $Force.IsPresent -list $BodyList
    $Body = BuildXtremJson -list $BodyList
    
    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -Body $Body -GetProperty $GetProperty -XtremClusterName $XtremClusterName  -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function Resume-XtremRemoteProtectionSession {
 <#
    .DESCRIPTION
    Resumes the specified remote protection session by ID.
     
    .PARAMETER ProtectionSessionId
    ID or GUID of the remote protection session
         
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Resume-XtremRemoteProtectionSession -ProtectionSessionId 1
  #>

    [CmdletBinding()]
    [Alias('xmsRemoteProtectionResume')]
    Param (
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'remote-protections' name })] 
        $ProtectionSessionId,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    $state = getRemoteProtectionState($ProtectionSessionId)
    if ($state -ne 'suspended') {
        Write-Host "Session state is [$state] cannot call $($MyInvocation.MyCommand)" -ForegroundColor Red
        return
    }
    initCommand
    
    $Route = '/commands/remote-protections/resume/'
    
    $Route, $GetProperty = SetParametersForRequest $Route $ProtectionSessionId
    
    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -GetProperty $GetProperty -XtremClusterName $XtremClusterName -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function Start-XtremRemoteProtectionSessionFailover {
 <#
    .DESCRIPTION
    Starts failover of the specified remote protection session by ID.
     
    .PARAMETER ProtectionSessionId
    ID or GUID of the remote protection session.
 
    .PARAMETER Type
    Type of failover, select one of the following: 'Using latest snapshot set', 'Use test copy snapshot set', 'Sync and failover', 'Specific snapshot set'
 
    .PARAMETER SnapshotSetName
    Name of specific snapshot set (if $type 'Specific snapshot set' is selected).
 
    .PARAMETER StartProtection
    Start protection after failover.
         
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON.
 
    .EXAMPLE
    Start-XtremRemoteProtectionSessionFailover -ProtectionSessionId 1 -Type 'Sync after failover'
  #>

    [CmdletBinding()]
    [Alias('xmsRemoteProtectionFailover')]
    Param (
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'remote-protections' name })] 
        $ProtectionSessionId,
        [Parameter()]
        [ValidateSet('Using latest snapshot set', 'Use test copy snapshot set', 'Sync and failover', 'Specific snapshot set')]
        $Type = 'Using latest snapshot set',
        [Parameter()]
        [object]$SnapshotSetName,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$StartProtection,
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/commands/remote-protections/failover/'
    
    $Route, $GetProperty = SetParametersForRequest $Route $ProtectionSessionId

    $BodyList = @{ }
    if ($Type -eq 'Specific snapshot set'){
        AddIfExists -name "snapshot-set-id" -value $SnapshotSetName -list $BodyList
    }else{
        if ($Type -eq 'Using latest snapshot set') { $Selection = 'using_latest_snapshot_set' }
        if ($Type -eq 'Use test copy snapshot set'){ $Selection = 'use_test_copy_snapshot_set'}
        if ($Type -eq 'Sync and failover'){ $Selection = 'sync_and_failover'}
        AddIfExists -name "snapshot-set-selection" -value $Selection -list $BodyList
        
    }
    AddIfExists -name "start-replication-with-failover" -value $StartProtection.IsPresent -list $BodyList
    
    $Body = BuildXtremJson -list $BodyList
    
    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -GetProperty $GetProperty -Body $Body -XtremClusterName $XtremClusterName  -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function Start-XtremRemoteProtectionTestCopy {
 <#
    .DESCRIPTION
    Starts test copy.
     
    .PARAMETER ProtectionSessionId
    ID or name of the remote protection session
 
    .PARAMETER UsingLatestSnapshotSet
    Choose the latest snapshot set automatically.
 
    .PARAMETER SnapshotSetId
    Selected remote protection snapshot set name or Id.
         
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Start-XtremRemoteProtectionTestCopy -ProtectionSessionId mySession1 -SnapshotSet sSet1
 
    .EXAMPLE
    Start-XtremRemoteProtectionTestCopy -ProtectionSessionId mySession1 -UsingLatestSnapshotSet
  #>

    [CmdletBinding()]
    [Alias('xmsRemoteProtectionTestCopyStart')]
    Param (
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'remote-protections' name })] 
        $ProtectionSessionId,
        [Parameter(ParameterSetName = 'latest')]
        [switch]$UsingLatestSnapshotSet,
        [Parameter(ParameterSetName = 'selected')]
        [Argumentcompleter( { fillFunc 'completeRSnapSets' $args 'ProtectionSessionId' })] 
        $SnapshotSetId,
        [Parameter()]
        [object]$Session = (Get-XtremDefaultSession),
        [Parameter()]
        $XtremClusterName = (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = "/commands/remote-protections/test-copy-start/"
    $Route, $GetProperty = SetParametersForRequest $Route $ProtectionSessionId

    $BodyList = @{ }
    if ($UsingLatestSnapshotSet.IsPresent) {
        AddIfExists -name "snapshot-set-selection" -value "using_latest_snapshot_set" -list $BodyList
    }else{
        AddIfExists -name "snapshot-set-id" -value $SnapshotSetId -list $BodyList

    }
    $Body = BuildXtremJson -list $BodyList
    
    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -GetProperty $GetProperty -Body $Body -XtremClusterName $XtremClusterName  -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function Finish-XtremRemoteProtectionTestCopy {
 <#
    .DESCRIPTION
    Finishes test copy.
     
    .PARAMETER ProtectionSessionId
    ID or name of the remote protection session
         
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Finish-XtremRemoteProtectionTestCopy mySession1
  #>

    [CmdletBinding()]
    [Alias('xmsRemoteProtectionTestCopyFinish')]
    Param (
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'remote-protections' name })] 
        $ProtectionSessionId,
        [Parameter()]
        [object]$Session = (Get-XtremDefaultSession),
        [Parameter()]
        $XtremClusterName = (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = "/commands/remote-protections/test-copy-finish/"
    $Route, $GetProperty = SetParametersForRequest $Route $ProtectionSessionId

    $BodyList = @{ }
    $Body = BuildXtremJson -list $BodyList
    
    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -GetProperty $GetProperty -Body $Body -XtremClusterName $XtremClusterName  -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function New-XtremRemoteProtectionBookMark {
 <#
    .DESCRIPTION
    Bookmark executes immediate replication.
     
    .PARAMETER ProtectionSessionId
    ID or GUID of the remote protection session
 
    .PARAMETER Name
    Bookmark name
 
    .PARAMETER RetentionTime
    Retention time
         
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    New-XtremRemoteProtectionBookMark -ProtectionSessionId 1
 
    .EXAMPLE
    New-XtremRemoteProtectionBookMark -ProtectionSessionId 1 -name 'newBm5'
  #>

    [CmdletBinding()]
    [Alias('xmsRemoteProtectionBookmark')]
    Param (
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'remote-protections' name })] 
        $ProtectionSessionId,
        [Parameter()]
        [ValidatePattern("^[^\[\]&\(\)`";,<>'/]+$")] 
        [string]$Name,
        [Parameter()]
        [System.Nullable[Int]]$RetentionTime = 0,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = "/commands/remote-protections/replicate-now/"
    $Route, $GetProperty = SetParametersForRequest $Route $ProtectionSessionId

    $BodyList = @{ }
    AddIfExists -name "bookmark-name" -value $Name -list $BodyList
    AddIfExists -name "retention-time" -value $RetentionTime -list $BodyList
    $Body = BuildXtremJson -list $BodyList
    
    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -GetProperty $GetProperty -Body $Body -XtremClusterName $XtremClusterName  -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function Set-XtremLocalProtectionSession {
 <#
    .DESCRIPTION
    This command is used to modify properties of the specified local protection session.
     
    .PARAMETER LocalProtectionId
    The ID of the local protection object.
     
    .PARAMETER NewProtectionSessionName
 
    .PARAMETER schedule
    For local protection the client can be either rpo or schedule. Rpo is the only option allowed for remote protection only.
 
    .PARAMETER Local Protection Type
     
    .PARAMETER Suffix
    Specifies the suffix to be used for the volume (snapshots) being created. Local protection only.
 
    .PARAMETER SnapshotObjectId
     
    .PARAMETER SnapshotObjectType
     
    .PARAMETER RetentionPolicyId
     
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Set-XtremLocalProtectionSession -Name test
  #>

    [CmdletBinding()]
    [Alias('xmsLocalProtectionModify')]
    Param (
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'local-protections' name })] 
        $LocalProtectionId,
        [Parameter()]
        [ValidatePattern("^[^\[\]&\(\)`";,<>'/]+$")] 
        $NewProtectionSessionName,
        [Parameter()]
        $Schedule,
        [parameter()]
        $RetentionPolicyId,
        [parameter()]
        $SnapshotObjectId,
        [Parameter()]
        $Suffix,
        [Parameter()]
        [ValidateSet('Volume', 'ConsistencyGroup')]
        $SnapshotObjectType,
        [Parameter()]
        [ValidateSet('interval', 'explicit')]
        $LocalProtectionType,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/local-protections'
    
    $BodyList = @{ }
    $Route, $GetProperty = SetParametersForRequest $Route $LocalProtectionId
    
    AddIfExists -name "new-protection-session-name" -value $SnappedObjectId -list $BodyList
    AddIfExists -name "schedule" -value $schedule -list $BodyList
    AddIfExists -name "retention-policy-id" -value $RetentionPolicyId -list $BodyList
    AddIfExists -name "suffix" -value $Suffix -list $BodyList
    AddIfExists -name "snapshot-object-type" -value $SnapshotObjectType -list $BodyList
    AddIfExists -name "snapshot-object-id" -value $SnapshotObjectId -list $BodyList
    AddIfExists -name "local-protection-type" -value $SnapshotObjectId -list $BodyList
    
    $Body = BuildXtremJson -list $BodyList
    
    $result = NewXtremRequest -Method POST -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $Body -GetProperty $GetProperty -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}


Function Remove-XtremLocalProtectionSession {
  <#
    .DESCRIPTION
     Removes the local-protection session and all its associated objects.
     
    .PARAMETER LocalProtectionId
    Id/Guid of the local protection
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Remove-XtremLocalProtectionSession LocalProtectionId 1
  #>

    [cmdletbinding()]
    [Alias('xmsLocalProtectionRemove')]
    Param (
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Alias("Name", "Index")]
        [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'local-protections' name })] 
        $LocalProtectionId,
        [Parameter()]
        [bool]$Confirm =  (Get-XtremDefaultSession)._XtremCLIMode,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    
    $confirmed = IsConfirmed $Confirm
    if (!$confirmed) {
        return
    }
    initCommand
    $Route = '/types/local-protections'
    $Route, $GetProperty = SetParametersForRequest $Route $LocalProtectionId
    
    $BodyList = @{ }
    
    $result = NewXtremRequest -Method DELETE -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $BodyList -GetProperty $GetProperty -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function Remove-XtremRemoteProtectionSession {
  <#
    .DESCRIPTION
    Removes the remote-protection session and target volumes.
     
    .PARAMETER ProtectionSessionId
    Id or name of the remote protection session
 
    .PARAMETER RemoveTargetVolumes
    Only valid for remote prortection.
 
    .PARAMETER Force
    Allows invoking a one sided removal incase of no-connectivity to the peer XMS.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Remove-XtremRemoteProtectionSession myTestSession1
  #>

    
    [cmdletbinding()]
    [Alias('xmsRemoteProtectionRemove')]
    Param (
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Alias("Name", "Index")]
        [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'remote-protections' name })] 
        $ProtectionSessionId,
        [Parameter()]
        [bool]$RemoveTargetVolumes,
        [Parameter()]
        [bool]$Force,
        [Parameter()]
        [bool]$Confirm =  (Get-XtremDefaultSession)._XtremCLIMode,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    $confirmed = IsConfirmed $Confirm
    if (!$confirmed) {
        return
    }
    initCommand
    $Route = '/types/remote-protections'
    $Route, $GetProperty = SetParametersForRequest $Route $ProtectionSessionId
    
    $BodyList = @{ }
    
    AddIfExists -name "force" -value $Force -list $BodyList
    AddIfExists -name "remove-target-volumes" -value $RemoveTargetVolumes -list $BodyList
    
    $result = NewXtremRequest -Method DELETE -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $BodyList -GetProperty $GetProperty -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}


# Function Get-XtremRemoteProtectionVolumePairs {
# <#
# .DESCRIPTION
# Shows all volume pairs related to a specified remote protection sesion.

# .PARAMETER Properties
# Array of properties requested from this call.

# .PARAMETER ShowRest
# Return an object represents the REST operation including URI , Method and JSON

# .EXAMPLE
# Get-XtremRemoteProtectionVolumePairs
# #>
    
# [cmdletbinding()]
# [Alias('xmsRemoteProtectionListVolumePairs')]
# Param (
# [parameter()]
# $XtremClusterName = (Get-XtremDefaultSession)._XtremClusterName,
# [Parameter()]
# [Alias("Properties")]
# [string[]]$Property = $ProtectionVolumePairsDefaultProperties,
# [Parameter()]
# [object]$Session = (Get-XtremDefaultSession),
# [Parameter()]
# [switch]$ShowRest
# )
# initCommand
# $Route = '/types/volume-pairs'
    
# $result = NewXtremRequest -Method GET -Endpoint $Route -XtremClusterName $XtremClusterName -Session $Session -Properties $Property -ShowRest:$ShowRest.IsPresent
        
# $result = formatOutPut $Property $result
    
# finalizeCommand
# return $result
# }


# Function Get-XtremRemoteProtectionVolumePair {
# <#
# .DESCRIPTION
# Shows all volume pairs related to a specified remote protection session.

# .PARAMETER ProtectionSessionId
# The name/index or guid of an session id.

# .PARAMETER Properties
# Array of properties requested from this call.

# .PARAMETER ShowRest
# Return an object represents the REST operation including URI , Method and JSON

# .EXAMPLE
# Get-XtremRemoteProtectionVolumePair SessName
# #>
    
# [cmdletbinding()]
# [Alias('xmsRemoteProtectionGetVolumePairs')]
# Param (
# [parameter()]
# $XtremClusterName = (Get-XtremDefaultSession)._XtremClusterName,
# [Alias("Name", "Index")]
# [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
# [Argumentcompleter( { doComplete $args 'remote-protections' name })]
# $ProtectionSessionId,
# [Parameter()]
# [Alias("Properties")]
# [string[]]$Property = $ProtectionVolumePairsDefaultProperties,
# [Parameter()]
# [object]$Session = (Get-XtremDefaultSession),
# [Parameter()]
# [switch]$ShowRest
# )
# initCommand
# $Route = '/types/volume-pairs'
# $Route, $GetProperty = SetParametersForRequest $Route $ProtectionSessionId
    
# $result = NewXtremRequest -Method GET -Endpoint $Route -XtremClusterName $XtremClusterName -Session $Session -GetProperty $GetProperty -Properties $Property -ShowRest:$ShowRest.IsPresent

# $result = formatOutPut $Property $result
    
# finalizeCommand
# return $result
# }


# Function New-XtremRemoteProtectionVolumePairs {
# <#
# .DESCRIPTION
# Adds Volume Pair to RM. One or more volume pairs are added in this command.
    
# .PARAMETER SessionID

# .PARAMETER VolumePairName
    
# .PARAMETER SourceVolumeId

# .PARAMETER TargetVolumeId

# .PARAMETER SourceXMSName
    
# .PARAMETER SourceClusterId
    
# .PARAMETER TargetXMSName
    
# .PARAMETER TargetClusterId

# .EXAMPLE
# New-XtremRemoteProtectionVolumePairs -Name test
# #>
# [CmdletBinding()]
# [Alias('xmsRemoteProtectionCreateVolumePair')]
# Param (
# [Parameter()]
# $XtremClusterName = (Get-XtremDefaultSession)._XtremClusterName,
# [Parameter()]
# $VolumePairName,
# [Parameter()]
# $SessionID,
# [Parameter()]
# $SourceVolumeId,
# [parameter()]
# $TargetVolumeId,
# [Parameter()]
# $SourceXMSName,
# [Parameter()]
# $SourceClusterId,
# [Parameter()]
# $TargetXMSName,
# [Parameter()]
# $TargetClusterId,
# [Parameter()]
# [object]$Session = (Get-XtremDefaultSession),
# [Parameter()]
# [switch]$ShowRest
# )
# initCommand
# $Route = '/types/volume-pairs'
    
# $BodyList = @{ }
    
# AddIfExists -name "protection-session-id" -value $SessionId -list $BodyList
# AddIfExists -name "source-vol-id" -value $SourceVolumeId-list $BodyList
# AddIfExists -name "target-vol-id" -value $TargetVolumeId-list $BodyList
# AddIfExists -name "volume-pair-name" -value $VolumePairName -list $BodyList
# AddIfExists -name "source-xms-name" -value $SourceXMSName-list $BodyList
# AddIfExists -name "source-cluster-id" -value $SourceClusterId-list $BodyList
    
# $Body = BuildXtremJson -list $BodyList
    
# $result = NewXtremRequest -Method POST -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $Body -ShowRest:$ShowRest.IsPresent

# finalizeCommand
# return $result
# }

# Function Remove-XtremRemoteProtectionVolumePairs {
# <#
# .DESCRIPTION
# Removes Volume Pairs specified in list.
    
# .PARAMETER VolumePair
# Id/Guid of the remote protection

# .PARAMETER Force
# Allows invoking a one sided removal incase of no-connectivity to the peer XMS.

# .PARAMETER ShowRest
# Return an object represents the REST operation including URI , Method and JSON

# .EXAMPLE
# Remove-XtremRemoteProtectionVolumePairs
# #>
    
# [cmdletbinding()]
# [Alias('xmsRemoteProtectionRemoveVolumePair')]
# Param (
# [parameter()]
# $XtremClusterName = (Get-XtremDefaultSession)._XtremClusterName,
# [Alias("Name", "Index")]
# [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
# $VolumePair,
# [Parameter()]
# $VolumePairIdList,
# [Parameter()]
# [bool]$Force,
# [Parameter()]
# [bool]$Confirm = (Get-XtremDefaultSession)._XtremCLIMode,
# [Parameter()]
# [object]$Session = (Get-XtremDefaultSession),
# [Parameter()]
# [switch]$ShowRest
# )
# $confirmed = IsConfirmed $Confirm
# if (!$confirmed) {
# return
# }
# initCommand
# $Route = '/types/volume-pairs'
# $Route, $GetProperty = SetParametersForRequest $Route $VolumePair
    
# $BodyList = @{ }
    
# AddIfExists -name "force" -value $Force -list $BodyList
    
# $result = NewXtremRequest -Method DELETE -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $BodyList -GetProperty $GetProperty -ShowRest:$ShowRest.IsPresent

# finalizeCommand
# return $result
# }

Function Get-XtremLocalProtectionSnapshotSets {
  <#
    .DESCRIPTION
    Lists the snapshotsets related to a specified local protection session.
 
    .PARAMETER LocalProtectionId
    The name of a local protection session.
 
    .PARAMETER Properties
    Array of properties requested from this call.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Get-XtremLocalProtectionSnapshotSets name
  #>

    
    [cmdletbinding()]
    [Alias('xmsLocalProtectionGetSnapshotSets')]
    Param (
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Alias("Name", "Index")]
        [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'local-protections' name })] 
        $LocalProtectionId,
        [Parameter()]
        $FromTime,
        [Parameter()]
        $ToTime,
        [Parameter()]
        [Alias("Properties")]
        [string[]]$Property = $LocalProtectionSnpashotSetDefaultProperties,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/snapshot-sets'

    $GetProperty = ''
    addGetPropertyIfExists 'filter' 'created-by-app:eq:local_protection'
    addGetPropertyIfExists 'session-name' $LocalProtectionId
    addGetPropertyIfExists 'from-time' $FromTime
    addGetPropertyIfExists 'to-time' $ToTime

    $result = NewXtremRequest -Method GET -Endpoint $Route -XtremClusterName $XtremClusterName -Session $Session  -GetProperty $GetProperty -Properties $Property -ShowRest:$ShowRest.IsPresent
    
    $result = formatOutPut $Property $result
    
    finalizeCommand
    return $result
}

Function Get-XtremRemoteProtectionSnapshotSets {
  <#
    .DESCRIPTION
    Lists Protection Snapshotsets relating to a specified remote-protection session, that exist on either source, target or both clusters.
 
    .PARAMETER ProtectionSessionId
    The name/index or guid of a Protection Session
 
    .PARAMETER FromTime
    Date time for earliest (oldest) snapshot set, if they exist.
 
    .PARAMETER ToTime
    Date time for newest (most recent) snapshot set, if they exist.
 
    .PARAMETER Properties
    Array of properties requested from this call.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Get-XtremRemoteProtectionSnapshotSets -ProtectionSessionId name/ID
 
    .EXAMPLE
    Get-XtremRemoteProtectionSnapshotSets name
 
    .EXAMPLE
    Get-XtremRemoteProtectionSnapshotSets name -Property name,guid,index
  #>

    
    [cmdletbinding()]
    [Alias('xmsRemoteProtectionGetSnapshotSets')]
    Param (
        [Alias("Name", "Index")]
        [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'remote-protections' name })] 
        $ProtectionSessionId,
        [parameter()]                                    
        $XtremClusterName = (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter()]
        $FromTime,
        [Parameter()]
        $ToTime,
        [Parameter()]
        [Alias("Properties")]
        [string[]]$Property = $RemoteProtectionSnpashotSetDefaultProperties,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/r-snapshot-sets'

    $GetProperty = ''
    addGetPropertyIfExists 'protection-session-id' $ProtectionSessionId 
    addGetPropertyIfExists 'from-time' $FromTime
    addGetPropertyIfExists 'to-time' $ToTime
    
    $result = NewXtremRequest -Method GET -Endpoint $Route -Session $Session -GetProperty $GetProperty -Properties $Property -ShowRest:$ShowRest.IsPresent

    $result = formatOutPut $Property $result
    
    finalizeCommand
    return $result
}

Function Set-XtremRemoteProtectionSnapshotSet {
 <#
    .DESCRIPTION
    Renames a snapshot set objects.
     
    .PARAMETER SnapsetId
    The ObjectID(index) of the snapshot set.
 
    .PARAMETER XMSName
 
    .PARAMETER NewName
    New name for the snapshot set.
     
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Set-XtremRemoteProtectionSnapshotSet 2002844 -NewName test
  #>

    [CmdletBinding()]
    [Alias('xmsRemoteProtectionModifySnapshotSet')]
    Param (
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        $SnapSetID,
        [Parameter()]
        [ValidatePattern("^[^\[\]&\(\)`";,<>'/]+$")] 
        $NewName,
        [Parameter()]
        $XMSName,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/r-snapshot-sets'
    
    $BodyList = @{ }
    $Route, $GetProperty = SetParametersForRequest $Route $SnapSetID
    
    AddIfExists -name "xms-name" -value $XMSName -list $BodyList
    AddIfExists -name "cluster-id" -value $XtremClusterName -list $BodyList
    AddIfExists -name "snapshot-set-id" -value $SnapSetID -list $BodyList
    AddIfExists -name "new-name" -value $NewName -list $BodyList
    
    $Body = BuildXtremJson -list $BodyList
    
    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $Body -GetProperty $GetProperty -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function Get-XtremProtectionRetentionPolices {
  <#
    .DESCRIPTION
    Show protection retention policies.
 
    .PARAMETER Properties
    Array of properties requested from this call.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Get-XtremProtectionRetentionPolicies
  #>

    
    [cmdletbinding()]
    [Alias('xmsRetentionPolicyList')]
    Param (
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter()]
        [Alias("Properties")]
        [Argumentcompleter( { doComplete $args 'retention-policies' prop })] 
        [string[]]$Property = $ProtectionRetentionPoliciesDefaultProperties,
        [parameter()]
        [Alias("Filters")]
        [Argumentcompleter( { doComplete $args 'retention-policies' filter })] 
        [array]$Filter,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/retention-policies'
    
    $result = NewXtremRequest -Method GET -Endpoint $Route -XtremClusterName $XtremClusterName -Session $Session -Properties $Property -Filters $Filter -ShowRest:$ShowRest.IsPresent

    $result = formatOutPut $Property $result
    
    finalizeCommand
    return $result
}

Function Get-XtremProtectionRetentionPolicy {
  <#
    .DESCRIPTION
    Show protection retention policy
 
    .PARAMETER RetentionPolicyId
    The name/index or guid of a RetentionPolicy
 
    .PARAMETER Properties
    Array of properties requested from this call.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Get-XtremRemoteProtectionIpLink -IpLink name
  #>

    
    [cmdletbinding()]
    [Alias('xmsRetentionPolicyGet')]
    Param (
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Alias("Name", "Index")]
        [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'retention-policies' name })] 
        $RetentionPolicyId,
        [Parameter()]
        [Alias("Properties")]
        [Argumentcompleter( { doComplete $args 'retention-policies' prop })] 
        [string[]]$Property,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/retention-policies'
    $Route, $GetProperty = SetParametersForRequest $Route $RetentionPolicyId
    
    $result = NewXtremRequest -Method GET -Endpoint $Route -XtremClusterName $XtremClusterName -Session $Session -GetProperty $GetProperty -Properties $Property -ShowRest:$ShowRest.IsPresent

    $result = formatOutPut $Property $result
    
    finalizeCommand
    return $result
}

Function New-XtremProtectionRetentionPolicy {
 <#
    .DESCRIPTION
    Adds a Retention Policy to a local or remote clusters.
     
    .PARAMETER Name
    This is the name of the retention_policy. It must be unique in the cluster namespace.
     
    .PARAMETER ShortPeriodDuration
    The duration of the short term consolidation period in units of: "d" for days, "h" for hours, "m" for minutes.
    Range is 1 to 500 (MAX_RETENTION_DURATION_VALUE).
    No mix between units. No decimal number allowed, only integers.
     
    .PARAMETER ShortPeriodCopies
    Number of copies of snapsets in short retention period will be retained. Range is 1 to 500 (MAX_RETENTION_DURATION_COPIES).
     
    .PARAMETER MiddlePeriodDuration
    The duration of the middle term consolidation period in units of: "d" for days, "h" for hours, "m" for minutes.
    Range is 1 to 500 (MAX_RETENTION_DURATION_VALUE).
    No mix between units. No decimal number allowed, only integers.
     
    .PARAMETER MiddlePeriodCopies
    Middle term retention copies. Range for valid period is 1 to 500 (MAX_RETENTION_DURATION_COPIES). Value of zero (0) is used to indicate that the period is not in use.
     
    .PARAMETER LongPeriodDuration
    The duration of the long term period in units of: "d" for days, "h" for hours, "m" for minutes.
    Range is 1 to 500 (MAX_RETENTION_DURATION_VALUE).
    No mix between units. No decimal number allowed, only integers.
    The value of zero (0) indicates this period is not used.
     
    .PARAMETER LongPeriodCopies
    Long term retention number of copies. Range for valid period is 1 to 500 (MAX_RETENTION_DURATION_COPIES). The value of zero (0) indicates that this period is not in use.
 
    .EXAMPLE
    New-XtremProtectionRetentionPolicy -Name test
  #>

    [CmdletBinding()]
    [Alias('xmsRetentionPolicyCreate')]
    Param (
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'retention-policies' name })]
        [ValidatePattern("^[^\[\]&\(\)`";,<>'/]+$")] 
        $Name,
        [Parameter()]
        $XMSName,
        [Parameter()]
        $ShortPeriodDuration,
        [Parameter()]
        $ShortPeriodCopies,
        [parameter()]
        $MiddlePeriodDuration,
        [Parameter()]
        $MiddlePeriodCopies,
        [Parameter()]
        $LongPeriodDuration,
        [Parameter()]
        $LongPeriodCopies,
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/retention-policies'
    
    $BodyList = @{ }

    if ($ShortPeriodDuration -and $ShortPeriodDuration.getType().name -eq 'Decimal') {
        $ShortPeriodDuration = "$($ShortPeriodDuration)d"
    }
    if ($MiddlePeriodDuration -and $MiddlePeriodDuration.getType().name -eq 'Decimal') {
        $MiddlePeriodDuration = "$($MiddlePeriodDuration)d"
    }
    if ($LongPeriodDuration -and $LongPeriodDuration.getType().name -eq 'Decimal') {
        $LongPeriodDuration = "$($LongPeriodDuration)d"
    }
    
    AddIfExists -name "retention-policy-name" -value $Name -list $BodyList
    AddIfExists -name "xms-id" -value $XMSName -list $BodyList
    AddIfExists -name "cluster-id" -value $XtremClusterName -list $BodyList
    AddIfExists -name "short-period-duration" -value $ShortPeriodDuration -list $BodyList
    AddIfExists -name "short-period-copies" -value $ShortPeriodCopies -list $BodyList
    AddIfExists -name "middle-period-duration" -value $MiddlePeriodDuration -list $BodyList
    AddIfExists -name "middle-period-copies" -value $MiddlePeriodCopies -list $BodyList
    AddIfExists -name "long-period-duration" -value $LongPeriodDuration -list $BodyList
    AddIfExists -name "long-period-copies" -value $LongPeriodCopies -list $BodyList
    
    $Body = BuildXtremJson -list $BodyList

    $result = NewXtremRequest -Method POST -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $Body -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function Copy-XtremProtectionRetentionPolicy {
 <#
    .DESCRIPTION
    Copies a Retention Policy or all Policies from one cluster to another
     
    .PARAMETER RetentionPolicyId
 
    .PARAMETER FromXMSName
     
    .PARAMETER FromClusterId
     
    .PARAMETER ToXMSName
 
    .PARAMETER ToRetentionPolicyId
 
    .PARAMETER CopyAll
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Copy-XtremProtectionRetentionPolicy -Name test
  #>

    [CmdletBinding()]
    [Alias('xmsRetentionPolicyCopy')]
    Param (
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'retention-policies' name })] 
        $RetentionPolicyId,
        [Parameter()]
        $FromXMSName,
        [Parameter()]
        $FromClusterId,
        [Parameter()]
        $ToXMSName,
          [Parameter()]
        $ToRetentionPolicyId,
        [Parameter()]
        [bool]$CopyAll = $false,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/retention-policies/copy'
    
    $BodyList = @{ }
    $Route, $GetProperty = SetParametersForRequest $Route $RetentionPolicyId
    
    AddIfExists -name "from-xms-name" -value $FromXMSName -list $BodyList
    AddIfExists -name "from-cluster-id" -value $FromClusterId-list $BodyList
    AddIfExists -name "to-xms-name" -value $ToXMSName -list $BodyList
    AddIfExists -name "to-cluster-id" -value $ToClusterId -list $BodyList
    AddIfExists -name "copy-all" -value $CopyAll-list $BodyList
    
    $Body = BuildXtremJson -list $BodyList
    
    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $Body -GetProperty $GetProperty -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function Set-XtremProtectionRetentionPolicy {
 <#
    .DESCRIPTION
    Modifies a Retention Policy.
     
    .PARAMETER ShortPeriodDuration
    The duration of the short term consolidation period in units of: "d" for days, "h" for hours, "m" for minutes.
    Range is 1 to 500 (MAX_RETENTION_DURATION_VALUE).
    No mix between units. No decimal number allowed, only integers.
     
    .PARAMETER ShortRetentionCopies
    Number of copies of snapsets in short retention period will be retained. Range is 1 to 500 (MAX_RETENTION_DURATION_COPIES).
     
    .PARAMETER MiddlePeriodDuration
    The duration of the middle term consolidation period in units of: "d" for days, "h" for hours, "m" for minutes.
    Range is 1 to 500 (MAX_RETENTION_DURATION_VALUE).
    No mix between units. No decimal number allowed, only integers.
     
    .PARAMETER MiddleRetentionCopies
    Middle term retention copies. Range for valid period is 1 to 500 (MAX_RETENTION_DURATION_COPIES). Value of zero (0) is used to indicate that the period is not in use.
     
    .PARAMETER LongPerioudDuration
    The duration of the long term period in units of: "d" for days, "h" for hours, "m" for minutes.
    Range is 1 to 500 (MAX_RETENTION_DURATION_VALUE).
    No mix between units. No decimal number allowed, only integers.
    The value of zero (0) indicates this period is not used.
     
    .PARAMETER LongRetentionCopies
    Long term retention number of copies. Range for valid period is 1 to 500 (MAX_RETENTION_DURATION_COPIES). The value of zero (0) indicates that this period is not in use.
 
 
    .EXAMPLE
    Set-XtremProtectionRetentionPolicy -Name test
  #>

    [CmdletBinding()]
    [Alias('xmsRetentionPolicyModify')]
    Param (
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'retention-policies' name })] 
        $RetentionPolicyId,
        [Parameter()]
        [ValidatePattern("^[^\[\]&\(\)`";,<>'/]+$")] 
        $newPolicyName,
        [Parameter()]
        $ShortPeriodDuration,
        [Parameter()]
        $ShortPeriodCopies,
        [parameter()]
        $MiddlePeriodDuration,
        [Parameter()]
        $MiddlePeriodCopies,
        [Parameter()]
        $LongPeriodDuration,
        [Parameter()]
        $LongPeriodCopies,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/retention-policies'
    
    $BodyList = @{ }

    $rpIndex = (Invoke-XtremGetRequest "/types/retention-policies" index -filter "name:eq:$RetentionPolicyId").index

    $Route += "/$rpIndex"

    if ($ShortPeriodDuration -and $ShortPeriodDuration.getType().name -eq 'Decimal') {
        $ShortPeriodDuration = "$($ShortPeriodDuration)d"
    }
    if ($MiddlePeriodDuration -and $MiddlePeriodDuration.getType().name -eq 'Decimal') {
        $MiddlePeriodDuration = "$($MiddlePeriodDuration)d"
    }
    if ($LongPeriodDuration -and $LongPeriodDuration.getType().name -eq 'Decimal') {
        $LongPeriodDuration = "$($LongPeriodDuration)d"
    }
    
    AddIfExists -name "retention-policy-name" -value $newPolicyName -list $BodyList
    AddIfExists -name "cluster-id" -value $XtremClusterName -list $BodyList
    AddIfExists -name "short-period-duration" -value $ShortPeriodDuration -list $BodyList
    AddIfExists -name "short-period-copies" -value $ShortPeriodCopies -list $BodyList
    AddIfExists -name "middle-period-duration" -value $MiddlePeriodDuration -list $BodyList
    AddIfExists -name "middle-period-copies" -value $MiddlePeriodCopies -list $BodyList
    AddIfExists -name "long-period-duration" -value $LongPeriodDuration -list $BodyList
    AddIfExists -name "long-period-copies" -value $LongPeriodCopies -list $BodyList
    
    $Body = BuildXtremJson -list $BodyList
    
    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $Body -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Function Remove-XtremProtectionRetentionPolicy {
  <#
    .DESCRIPTION
    Removes a Retention Policy from the RM and the clusters.
     
    .PARAMETER RetentionPolicyId
    Name or Id of the retention policy
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Remove-XtremProtectionRetentionPolicy myRPname
  #>

    
    [cmdletbinding()]
    [Alias('xmsRetentionPolicyRemove')]
    Param (
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Alias("Name", "Index")]
        [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'retention-policies' name })] 
        $RetentionPolicyId,
        [Parameter()]
        [bool]$Confirm =  (Get-XtremDefaultSession)._XtremCLIMode,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    $confirmed = IsConfirmed $Confirm
    if (!$confirmed) {
        return
    }
    initCommand
    
    $Route = '/types/retention-policies'
    $Route, $GetProperty = SetParametersForRequest $Route $RetentionPolicyId
    
    $result = NewXtremRequest -Method DELETE -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $BodyList -GetProperty $GetProperty -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

function getRemoteProtectionState($id){
    $sess = Get-XtremRemoteProtectionSession $id -prop replication-state
    if($sess){
        return $sess."replication-state"
    }
}

Function Get-XtremSchedulers {
<#
    .DESCRIPTION
    Displays the list of all Schedulers and their defined parameters.
 
    .PARAMETER Properties
    Array of properties requested from this call.
 
    .PARAMETER Filters
    Array of filters for this call.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Get-XtremSchedulers
  #>

    [cmdletbinding()]
    [Alias('xmsSchedulerList')]
    Param (
        [parameter()]
        [Alias("Properties")]
        [Argumentcompleter( { doComplete $args 'schedulers' prop })] 
        [string[]]$Property = $SchedulersDefaultProperties,
        [parameter()]
        [Alias("Filters")]
        [Argumentcompleter( { doComplete $args 'schedulers' filter })] 
        [string[]]$Filter,
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest,
        [Parameter()]
        [switch]$Full = $false
        
    )
    initCommand
    $Route = '/types/schedulers'

    if ($Full) { $Property = '' }
    
    $result = NewXtremRequest -Method GET -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Properties $Property -Filters $Filter -ShowRest:$ShowRest.IsPresent -Multi -Full:$Full.IsPresent
    
    $result = formatOutPut $Property $result
    
    finalizeCommand
    return $result
}

Function Get-XtremScheduler {
<#
    .DESCRIPTION
    Displays details of the selected Scheduler.
 
    .PARAMETER SchedulerName
    Scheduler 's name or index number.
 
    .PARAMETER Properties
    Array of properties requested from this call.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Get-XtremScheduler -SchedulerName name
  #>

    [cmdletbinding()]
    [Alias('xmsSchedulerGet')]
    Param (
        [Alias("Name", "Index")]
        [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'schedulers' name })] 
        $SchedulerName,
        [Parameter()]
        [Alias("Properties")]
        [Argumentcompleter( { doComplete $args 'schedulers' prop })] 
        [string[]]$Property,
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/schedulers'
    $Route, $GetProperty = SetParametersForRequest $Route $SchedulerName
    
    $result = NewXtremRequest -Method GET -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -GetProperty $GetProperty -Properties $Property -ShowRest:$ShowRest.IsPresent
    
    $result = formatOutPut $Property $result
    
    finalizeCommand
    return $result
}

Function Remove-XtremScheduler {
<#
    .DESCRIPTION
    Enables you to delete a Scheduler.
 
    .PARAMETER SchedulerName
    Scheduler 's name or index number.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Remove-XtremScheduler -SchedulerName name
  #>

    
    [cmdletbinding()]
    [Alias('xmsSchedulerRemove')]
    Param (
        [Alias("Name", "Index")]
        [parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'schedulers' name })] 
        $SchedulerName,
        [parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [bool]$Confirm =  (Get-XtremDefaultSession)._XtremCLIMode,
        [Parameter()]
        [switch]$ShowRest
    )
    
    $confirmed = IsConfirmed $Confirm
    if (!$confirmed) {
        return
    }
    initCommand
    $Route = '/types/schedulers'
    $Route, $GetProperty = SetParametersForRequest $Route $SchedulerName
    
    $result = NewXtremRequest -Method DELETE -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -GetProperty $GetProperty -ShowRest:$ShowRest.IsPresent
    
    finalizeCommand
    return $result
}

Function New-XtremScheduler {
 <#
    .DESCRIPTION
    Enables you to create a new Scheduler.
 
    .PARAMETER SchedulerName
    Scheduler's name.
 
    .PARAMETER SnapshotObjectType
    Snapped Object type: 'Volume', 'SnapSet' or 'ConsistencyGroup'.
 
    .PARAMETER SnapshotObjectId
    Snapped Object ID or name.
 
    .PARAMETER SnapshotType
    Write (regular) or readonly.
 
    .PARAMETER Suffix
    Text adjoined to the scheduler's stem name
 
    .PARAMETER SnapshotsToKeepTime
    The time period, for which a Snapshot should be saved. When the defined time has passed the cluster automatically removes the Snapshot. Int must be used.
 
    .PARAMETER SnapshotsToKeepNumber
    Number of Snapshots to be saved.
 
    .PARAMETER SchedulerType
    Schedule is specified explicitly or by intervals.
 
    .PARAMETER Day
    Scheduler's day. Can be 'Every day', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'.
 
    .PARAMETER Time
    Scheduler's time [hh:mm].
 
    .PARAMETER EnabledState
    Scheduler enable state
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    New-XtremScheduler myNewSc1 -SchedulerType explicit -SnapshotObjectType Volume -SnapshotsToKeepNumber 2 -Day 'Every day' -Time "20:14" -SnapshotObjectId myVol1
 
    .EXAMPLE
    New-XtremScheduler -SchedulerName sch2019_04_15 -SchedulerType explicit -SnapshotObjectId tempPSvol99 -SnapshotObjectType Volume -SnapshotsToKeepTime 36000 -Time 10:20 -Day 'Every day'
  #>

    [CmdletBinding()]
    [Alias('xmsSchedulerCreate')]
    Param (
        [Parameter(Mandatory = $true, Position = 0)]
        [ValidatePattern("^[^\[\]&\(\)`";,<>'/]+$")]
        [Argumentcompleter( { doComplete $args 'schedulers' name })] 
        [string]$SchedulerName,
        [Parameter(Mandatory = $true)]
        [ValidateSet( 'Volume', 'SnapSet', 'ConsistencyGroup')]
        [String]$SnapshotObjectType,
        [Parameter(Mandatory = $true)]
        [Argumentcompleter( { completeEntityName $args 'SnapshotObjectType' })]
        $SnapshotObjectId,
        [Parameter()]
        [ValidateSet( 'regular', 'readonly')]
        [String]$SnapshotType,
        [Parameter()]
        [String]$Suffix,
        [Parameter()]
        [int]$SnapshotsToKeepTime,
        [Parameter()]
        [AllowNull()]
        [System.Nullable[Int]]$SnapshotsToKeepNumber,
        [Parameter(Mandatory = $true)]
        [ValidateSet("interval", "explicit")]
        [string]$SchedulerType,
        [Parameter(Mandatory = $true)]
        [ValidateSet('Every day', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')]
        [string]$Day,
        [Parameter(Mandatory = $true)]
        [ValidatePattern("^\d\d:\d\d$")] 
        [string]$Time,
        [Parameter()]
        [string]$EnabledState,
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/schedulers'
    
    $BodyList = @{ }

    $dayNum = switch($Day){
        'Every day' {'0'}
        'Sunday'{'1'}
        'Monday'{'2'}
        'Tuesday'{'3'}
        'Wednesday'{'4'}
        'Thursday'{'5'}
        'Friday'{'6'}
        'Saturday' {'7'}
    }

    $theTime = $dayNum + ':' + $Time
    
    AddIfExists -name "cluster-id" -value $XtremClusterName -list $BodyList
    AddIfExists -name "snapshot-object-type" -value $SnapshotObjectType -list $BodyList
    AddIfExists -name "snapshot-type" -value $SnapshotType -list $BodyList
    AddIfExists -name "suffix" -value $Suffix -list $BodyList
    AddIfExists -name "snapshots-to-keep-time" -value $SnapshotsToKeepTime -list $BodyList
    AddIfExists -name "snapshot-object-id" -value $SnapshotObjectId -list $BodyList
    AddIfExists -name "snapshots-to-keep-number" -value $SnapshotsToKeepNumber -list $BodyList
    AddIfExists -name "scheduler-type" -value $SchedulerType -list $BodyList
    AddIfExists -name "time" -value $theTime -list $BodyList
    AddIfExists -name "enabled-state" -value $EnabledState -list $BodyList
    AddIfExists -name "scheduler-name" -value $SchedulerName -list $BodyList
    
    $Body = BuildXtremJson -list $BodyList
    
    $result = NewXtremRequest -Method POST -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $Body -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}


Function Set-XtremScheduler {
  <#
    .DESCRIPTION
    Enables you to modify a Scheduler
 
    .PARAMETER SchedulerName
    Scheduler's name or index number.
 
    .PARAMETER SnapshotObjectType
    Scheduler 's name or index number.
 
    .PARAMETER SnapshotType
    Write (default) or Read.
 
    .PARAMETER Suffix
    Text adjoined to the scheduler's stem name
 
    .PARAMETER SnapshotsToKeepTime
    The time period, in seconds, for which a Snapshot should be saved. When the defined time has passed the cluster automatically removes the Snapshot.
 
    .PARAMETER SnapshotObjectId
    Snapped Object ID.
 
    .PARAMETER SnapshotsToKeepNumber
    Number of Snapshots to be saved.
 
    .PARAMETER SchedulerType
    Schedule is specified explicitly or by intervals.
 
    .PARAMETER Day
    Scheduler's day. Can be 'Every day', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'.
 
    .PARAMETER Time
    Scheduler's time [hh:mm].
 
    .PARAMETER state
    Suspends or resumes Scheduler; 'enabled' or 'user-disabled'.
 
    .PARAMETER ShowRest
    Return an object represents the REST operation including URI , Method and JSON
 
    .EXAMPLE
    Set-XtremScheduler -SchedulerName 2 -Suffix TEST
  #>

    [CmdletBinding()]
    [Alias('xmsSchedulerModify')]
    Param (
        [Parameter(Mandatory = $true, Position = 0)]
        [Argumentcompleter( { doComplete $args 'schedulers' name })] 
        $SchedulerName,
        [Parameter(Mandatory = $true)]
        [ValidateSet( 'Volume', 'SnapSet', 'ConsistencyGroup')]
        [String]$SnapshotObjectType,
        [Parameter(Mandatory = $true)]
        [Argumentcompleter( { completeEntityName $args 'SnapshotObjectType' })]
        $SnapshotObjectId,
        [Parameter()]
        [ValidateSet( 'regular', 'readonly')]
        [String]$SnapshotType,
        [Parameter(Mandatory = $true)]
        [ValidateSet('Every day', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')]
        [string]$Day,
        [Parameter(Mandatory = $true)]
        [ValidatePattern("^\d\d:\d\d$")] 
        [string]$Time,
        [Parameter()]
        [String]$Suffix,
        [Parameter()]
        [String]$SnapshotsToKeepTime,
        [Parameter()]
        [AllowNull()]
        [System.Nullable[Int]]$SnapshotsToKeepNumber,
        [Parameter()]
        [ValidateSet("interval", "explicit")]
        [string]$SchedulerType,
        [Parameter()]
        $XtremClusterName =  (Get-XtremDefaultSession)._XtremClusterName,
        [Parameter()]
        [object]$Session =  (Get-XtremDefaultSession),
        [Parameter()]
        [switch]$ShowRest
    )
    initCommand
    $Route = '/types/schedulers'
    $Route, $GetProperty = SetParametersForRequest $Route $SchedulerName
    $BodyList = @{ }

    $dayNum = switch ($Day) {
        'Every day' { '0' }
        'Sunday' { '1' }
        'Monday' { '2' }
        'Tuesday' { '3' }
        'Wednesday' { '4' }
        'Thursday' { '5' }
        'Friday' { '6' }
        'Saturday' { '7' }
    }

    $theTime = $dayNum + ':' + $Time
    
    AddIfExists -name "cluster-id" -value $XtremClusterName -list $BodyList
    AddIfExists -name "snapshot-object-type" -value $SnapshotObjectType -list $BodyList
    AddIfExists -name "snapshot-type" -value $SnapshotType -list $BodyList
    AddIfExists -name "suffix" -value $Suffix -list $BodyList
    AddIfExists -name "snapshots-to-keep-time" -value $SnapshotsToKeepTime -list $BodyList
    AddIfExists -name "snapshot-object-id" -value $SnapshotObjectId -list $BodyList
    AddIfExists -name "snapshots-to-keep-number" -value $SnapshotsToKeepNumber -list $BodyList
    AddIfExists -name "scheduler-type" -value $SchedulerType -list $BodyList
    AddIfExists -name "time" -value $theTime -list $BodyList
    
    $Body = BuildXtremJson -list $BodyList
    
    $result = NewXtremRequest -Method PUT -Endpoint $Route -Session $Session -XtremClusterName $XtremClusterName -Body $Body -GetProperty $GetProperty -ShowRest:$ShowRest.IsPresent

    finalizeCommand
    return $result
}

Export-ModuleMember *-* -Alias *