Script Examples

Microsoft Platform Guide

Audience
Public
Source Type
Documentation

For automation, please check out the . Version 1.x (1.17) and the recently shipped 2.x (2.2), correspond to the version of the Rest API that is supported. The v2 SDK has cmdlets to initiate a Pod promote/demote, while the v1 SDK requires the use of the New-PfaCLICommand cmdlet to pass a command to the CLI.

Demotion Script Example SDK 1.17

# The disk resources of any applications or cluster roles on the Pod should be brought offline after the application is stopped.

# Before demoting the Pod, offline VMs, SQL DBs, and disks

# Offline DB dbprod-dr in the DR site

Invoke-Sqlcmd -InputFile c:\ps\repdismount.sql -QueryTimeout 3600 -ServerInstance 'ch2-barkz-03\qstance'

# Offline physical disk housing the SQL DB dbprod-dr in the DR site

Set-Disk -Number 6 -CimSession $cimsess -IsOffline $true
# Offline VM Exch02-dr in the DR site, requires Failover Cluster module

Stop-ClusterResource -Name "Virtual Machine Exch02"
# Offline CSV disk housing VM Exch02-dr in the DR site

Stop-ClusterResource -Name "Cluster Disk 5"
# Connect to Prod FlashArray #57 For examples on how to encrypt the password to a text file see ConvertTo-SecureString

$57 = Get-Content "C:\ps\57.txt" | ConvertTo-SecureString
# -IgnoreCertificateError should not be used when proper certificate configuration is used

$pfa57 = New-PfaArray -EndPoint 10.21.201.57 -UserName pureuser -Password $57 -IgnoreCertificateError
# Demote the Pod

New-PfaCLICommand -EndPoint 10.21.201.57 -UserName pureuser -Password $57 -CommandText "purepod demote qpodprod --quiesce"

Promotion Script Example SDK 1.17

# The disk resources of any applications or cluster roles on the Pod should be brought online after the Pod is Promoted.

# Connect to Prod FlashArray #57 For examples on how to encrypt the password to a text file see ConvertTo-SecureString

$130 = Get-Content "C:\ps\130.txt" | ConvertTo-SecureString
# -IgnoreCertificateError should not be used when proper certificate configuration is used

$pfa130 = New-PfaArray -EndPoint 10.21.201.130 -UserName pureuser -Password $130 -IgnoreCertificateError
# Promote the Pod

New-PfaCLICommand -EndPoint 10.21.201.130 -UserName pureuser -Password $130 -CommandText "purepod promote qpoddr"



do {

    Write-Host "Waiting for Promotion"

    Start-Sleep -Milliseconds 500

    $test = New-PfaCLICommand -EndPoint 10.21.201.130 -UserName pureuser -Password $130 -CommandText "purepod list qpoddr"

  

} while ($test | select-string -pattern "promoting")
# Online physical disk housing the SQL DB dbprod-dr in the DR site

Set-Disk -Number 6 -IsOffline $false

Set-Disk -Number 6 -IsReadOnly $false# Online DB dbprod-dr in the DR site

Invoke-Sqlcmd -InputFile c:\ps\repmount.sql -QueryTimeout 3600 -ServerInstance 'ch2-barkz-03\qstance'
#In the case of a Hyper-V Host, first online the Cluster Disk Resource, then any VMs on that CSV.

# Online CSV disk housing VM Exch02-dr in the DR site

Start-ClusterResource -Name "Cluster Disk 5"
# Online VM Exch02-dr in the DR site, requires Failover Cluster module

Start-ClusterResource -Name "Virtual Machine Exch02"

Demotion Script Example SDK 2.2

#The disk resources of any applications or cluster roles on the Pod should be brought offline after the application is stopped.

#Before demoting the Pod, offline VMs, SQL DBs, and then disks

#Offline DB dbprod-dr in the DR site

Invoke-Sqlcmd -inputfile c:\ps\repdismount.sql -QueryTimeout 3600 -ServerInstance 'ch2-barkz-03\qstance'

#Offline physical disk housing the SQL DB dbprod-dr in the DR site

Set-Disk -Number 6 -CimSession $cimsess -IsOffline $true

#Offline VM Exch02-dr in the DR site, requires Failover Cluster module

Stop-ClusterResource -name "Virtual Machine Exch02"

#Offline CSV disk housing VM Exch02-dr in the DR site

Stop-ClusterResource -name "Cluster Disk 5"

#Connect to the FlashArray with SDK 2.2. For OAUTH setup, see the Blog: Introducing the Pure FlashArray PowerShell SDK Version 2
#For examples on how to encrypt the password to a text file see ConvertTo-SecureString

#-IgnoreCertificateError should not be used when proper certificate configuration is used

$purepass = Get-Content "C:\ps\purepass.txt" | convertto-securestring

$pfa130 = Connect-Pfa2Array -EndPoint 10.21.201.130 -UserName pureuser -Password $purepass -IgnoreCertificateError

#demote the Pod

Update-Pfa2Pod -Array $pfa57 -Name qpodprod -RequestedPromotionState "demoted" -Quiesce $true

Promotion Script Example SDK 2.2

#The disk resources of any applications or cluster roles on the Pod should be brought online after the Pod is Promoted.

#Connect to the FlashArray with SDK 2.2. For OAUTH setup, see the Blog: Introducing the Pure FlashArray PowerShell SDK Version 2

#For examples on how to encrypt the password to a text file see ConvertTo-SecureString

#-IgnoreCertificateError should not be used when proper certificate configuration is used

$purepass = Get-Content "C:\ps\purepass.txt" | convertto-securestring

$pfa130 = Connect-Pfa2Array -EndPoint 10.21.201.130 -UserName pureuser -Password $purepass -IgnoreCertificateError

#Promote the Pod

Update-Pfa2Pod -Array $pfa130 -Name qdr2 -RequestedPromotionState "promoted"

#Get promotion status and stall until it is promoted.

#You do not want to online disks that have not been changed from READONLY status yet.



do{

   Write-Host "Waiting for Promotion"

   Start-Sleep -Milliseconds 500

   $test = (get-pfa2pod -array $pfa130 -name qdr2).promotionstatus

} while ($test |select-string -pattern "promoting")
Write-Host "Pod Promoted"

#Online physical disk housing the SQL DB dbprod-dr in the DR site

Set-Disk -Number 8 -CimSession $cimsess -IsOffline $false

Set-Disk -Number 8 -CimSession $cimsess -IsReadOnly $false

#Online DB dbprod-dr in the DR siteInvoke-Sqlcmd -inputfile c:\ps\repmount.sql -QueryTimeout 3600 -ServerInstance 'ch2-barkz-03\qstance'
#In the case of a Hyper-V Host, first online the Cluster Disk Resource, then any VMs on that CSV.

#Online CSV disk housing VM Exch02-dr in the DR site

#Start-ClusterResource -name "Cluster Disk 5"

#Online VM Exch02-dr in the DR site, requires Failover Cluster module

#Start-ClusterResource -name "Virtual Machine Exch02"

T-SQL Queries to Online & Offline a Database

ALTER DATABASE [dbprod-dr] SET OFFLINE WITH ROLLBACK IMMEDIATE

GO

In the above code block, the TSQL query to offline the database referenced in the invoke-sqlcmd SQL Server PowerShell cmdlet as repdismount.sql. For information on how to safely offline a production database, see ALTER DATABASE SET options.

ALTER DATABASE [dbprod-dr] SET ONLINE

GO

In the above code block, the TSQL query to online the database referenced in the invoke-sqlcmd SQL Server PowerShell cmdlet as repmount.sql.