Created
April 11, 2017 10:58
-
-
Save JamesWoolfenden/571097ea3eaaa91c3182aa4c67e57ed4 to your computer and use it in GitHub Desktop.
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
param( | |
[Parameter(Mandatory=$true)] | |
[string]$subscriptionName, | |
[Parameter(Mandatory=$true)] | |
[string]$serviceName, | |
[string]$slot="Staging") | |
Write-Output "$(Get-Date) - Selecting $SubscriptionName" | |
Select-Azuresubscription -SubscriptionName $SubscriptionName | |
if ($SubscriptionName -eq (Get-AzureSubscription -Current).SubscriptionName) | |
{ | |
Write-Output "$(Get-Date) - Selected $SubscriptionName" | |
} | |
else{ | |
throw "Failed to Set subscription to $SubscriptionName" | |
} | |
$service=Get-AzureService| where {$_.ServiceName -match $serviceName}| Get-AzureDeployment -Slot $Slot -ErrorAction Ignore | |
if (!($service)) | |
{ | |
Write-Warning "No service found for $serviceName in $SubscriptionName" | |
return | |
} | |
$Instances=$service.RoleInstanceList.InstanceName | |
if (!($Instances)) | |
{ | |
Write-Warning "No Instances found for $serviceName in $SubscriptionName" | |
return | |
} | |
else{ Write-Host "$(Get-Date) - Found $($Instances.count) instances for $serviceName for $slot "} | |
foreach($instance in $Instances) | |
{ | |
Write-Output "$(Get-Date) - Rebooting: $instance" | |
Write-Host "ReSet-AzureRoleInstance -ServiceName $serviceName -Slot $Slot -InstanceName $instance -reboot" | |
ReSet-AzureRoleInstance -ServiceName $serviceName -Slot $Slot -InstanceName $instance -reboot | |
while ((Get-AzureDeployment $ServiceName -Slot $slot).RoleInstanceList | Where-Object { $_.InstanceStatus -ne "ReadyRole" } | ft -Property RoleName, InstanceName, InstanceStatus ) | |
{ | |
Write-Host "$(Get-Date) - Waiting" -NoNewLine | |
Sleep 5 | |
Write-Host "..." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment