Last active
December 6, 2019 15:33
-
-
Save ljtill/e01bd15310f358d0dd22253d149511be to your computer and use it in GitHub Desktop.
Provides the ability to retrieve the current Storage Account replication status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -Modules Az.Accounts, Az.Storage | |
function Get-AzStorageAccountReplication() { | |
<# | |
.SYNOPSIS | |
Get-AzStorageAccountReplication | |
.DESCRIPTION | |
Retrieves the latest replication status for a given Storage Account (RA-GRS) | |
.EXAMPLE | |
Get-AzStorageAccountReplication -AccountName "" -AccountKey "" -Service "Blob" | |
#> | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory = $true)] | |
[ValidateNotNullOrEmpty()] | |
[string]$AccountName, | |
[Parameter(Mandatory = $true)] | |
[ValidateNotNullOrEmpty()] | |
[string]$AccountKey, | |
[Parameter(Mandatory = $true)] | |
[ValidateNotNullOrEmpty()] | |
[ValidateSet("Blob", "Table", "Queue")] | |
[string]$Service | |
) | |
begin { | |
Write-Verbose -Message ("Initiating function " + $MyInvocation.MyCommand + " begin") | |
$context = New-AzStorageContext -StorageAccountName $accountName -StorageAccountKey $accountKey | |
$token = (New-AzStorageAccountSASToken -Context $context -Service @("Blob","Table","Queue") -ResourceType Service -Permission "rl" -ExpiryTime ((Get-Date).AddHours(1)).ToUniversalTime()) | |
$token = $token.Replace("?", "") | |
$uri = "https://" + $accountName + "-secondary." + $service + ".core.windows.net/?restype=service&comp=stats&" + $token | |
} | |
process { | |
Write-Verbose -Message ("Initiating function " + $MyInvocation.MyCommand + " process") | |
try { | |
$response = Invoke-RestMethod -Uri $uri -Method "Get" -Headers $null -Body $null | |
[xml]$response = $response.Replace("", "") | |
$replication = $response.StorageServiceStats.GeoReplication | |
} | |
catch { | |
Write-Error -Exception $_.Exception | |
} | |
} | |
end { | |
Write-Verbose -Message ("Initiating function " + $MyInvocation.MyCommand + " end") | |
return $replication | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment