Checking the Status of an Azure Web App Swap using PowerShell

This past week I was working with a customer who wanted to check the status of a swap with an Azure Web App using TFS. One option would be to use the Swap deployment task and the other would be to query the status using PowerShell. In order to do so we query the Activity Log to get the status. The first line gets the format of the date in a format that the Azure SDK for PowerShell recognizes. The next line we get the current status.

  • The caller value is optional
  • We only need one record so we set the -MaxRecord to 1
  • The status we are looking for is Succeeded
  • We add the -ResourceId of the slot we are trying to swap
  • Finally we add the StartTime to be that of the current date

Next we loop through the wile statement until we finally get a result stating the swap succeeded and we exit the while loop.

$currentdate = Get-Date -Format o

$status = Get-AzureRmLog -Caller “jebrook@microsoft.com” -MaxRecord 1 -Status “Succeeded” -ResourceId “/subscriptions/7317be97-c6d6-4ef8-9173-809f4614654e/resourcegroups/jebrook-ResourceGroup/providers/Microsoft.Web/sites/jebrook-sqlwebapp/slots/test” -StartTime $currentdate -Verbose

while ($status.Status.Value -notcontains “Succeeded”)

{

$status = Get-AzureRmLog -Caller “jebrook@microsoft.com” -MaxRecord 1 -Status “Succeeded” -ResourceId “/subscriptions/7317be97-c6d6-4ef8-9173-809f4614654e/resourcegroups/jebrook-ResourceGroup/providers/Microsoft.Web/sites/jebrook-sqlwebapp/slots/test” -StartTime $currentdate -Verbose

$status

}

Write-Output “Completed”;