Azure App Services: Get Deployment Slots using PowerShell

By Saad Khamis

October 14, 2021

12317 views

In this blog I will share one way to get Deployment Slots for a single App Service or all App Services using PowerShell.

My blogs have relatively simple, and sometimes complex, examples and I’m hoping that you will be able to tailor them to your need or use them in your own scripts.

Prerequisites

  1. Install Azure PowerShell if you haven’t already.
  2. Install Azure Active Directory PowerShell module if you haven’t already.

Introduction

The goal of this blog is to show one way to accomplish a task. It is not to show how to write a perfect script, the perfect solution to a challenge or the perfect process to accomplish a task.

Using PowerShell, I will show you how to get deployment slots for:

  1. A single App Service.
  2. All App Services.

I will also show, for demonstration, how to display PowerShell cmdlet output in a table format.

PowerShell Cmdlets

  1. Connect-AzAccount Connect to Azure with an authenticated account for use with cmdlets from the Az PowerShell modules.
  2. Set-AzContext Sets the tenant, subscription, and environment for cmdlets to use in the current session.
  3. Get-AzWebApp Gets Azure Web Apps in the specified resource group.
  4. Get-AzWebAppSlot Gets an Azure Web App slot.

Sign in to Azure

  1. Sign in to Azure. If you have multiple subscriptions or tenants, make sure to sign in to the correct subscription.
  2. You can use Set-AzContext to set the tenant, subscription, and environment for cmdlets to use in the current session.

Get Deployment Slots for a single App Service

  1. Get-AzWebAppSlot cmdlet is used to get the Web App slots.

Get Deployment Slots for all App Services

  1. Use Get-AzWebApp to get a list of all App Services in the subscription.
  2. Initialize a variable, $OutTable, to save output.
  3. (a) For each App Service, (b) use Get-AzWebAppSlot to get a list of the App Service available slots.
  4. If the App does not have slots, add “No slots found” to $OutTable.
  5. For each App Service slot, add the required information to $OutTable.
  6. Display $OutTable.

Conclusion

In this blog we explored how to get Azure App Services Slots using PowerShell. We also explored how to output PowerShell cmdlet result as a table.

Did you find this blog easy to follow and helpful to you? Let me know in the comments below.

Disclaimer

Purpose of the code contained in blog is solely for learning and demo purposes. Author will not be held responsible for any failure or damages caused due to any other usage.

Comments

There's no comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

List all AWS Certificate Manager certificates

By Saad Khamis 14096 views July 31, 2024

Get all AWS EBS snapshots across all profiles and regions

By Saad Khamis 18454 views June 26, 2024