Azure portal provides an option to create additional deployment slots for your app to use for staging. This creates a copy of your app which you can publish to for testing and when you’re ready, swap this slot with the production slot. This method of creating a staging slot does not copy over all the files (app’s media or content) to the new slot which is sometimes necessary. To create a new slot with all the files copied over, you can use Azure PowerShell.

Install Azure-PowerShell & Connect to Azure Account

In PowerShell on your PC, install the Azure PowerShell module and connect it to your Azure account.

1
2
3
4
5
# Install Azure PowerShell
Install-Module -Name Az

#Connect to Azure. Opens browser sign-in
Connect-AzAccount

Clone Existing App to a New Slot

Once you’ve connected to your Azure account, get the details of your app and create a new slot. The parameter that lets you copy all the files to the new slot is -SourceWebApp in the last command below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# View Azure account details
Get-AzSubscription

# View all WebApps details
Get-AzWebApp

# View all slots in WebApp. This list will exclude the "production" slot
Get-AzWebAppSlot -ResourceGroupName resourcegroupname -name appservicename

# Assign details of existing slot to a variable. Change "production" to the name of the slot you want to clone.
$sourceAppSlot= Get-AzWebAppSlot -ResourceGroupName resourcegroupname -name appservicename -Slot production

# Clone $sourceAppSlot to a new slot. The "newslotname" should not exist.
New-AzWebAppSlot -ResourceGroupName resourcegroupname -Name appservicename -AppServicePlan appserviceplanname -SourceWebApp $sourceAppSlot -Slot newslotname