How to create a webapp slot without copying settings using PowerShell?

Vijay Kabbur 0 Reputation points
2024-05-23T09:02:37.6566667+00:00

I want to create a Slot for an Azure WebApp using PowerShell, without copying any settings from the main production slot.

The command I'm using is:

New-AzWebAppSlot -ResourceGroupName $ResourceGroup -Name $ApplicationName -Slot $SlotName -ErrorAction Stop

The variables $ResourceGroup, $ApplicationName and $SlotName have string values.

I'm expecting the new slot to not have any AppSettings, ConnectionStrings and PathMappings since I haven't used the -SourceWebApp parameter, but in reality when I run the command, the slot that gets created DOES have the values for AppSettings, ConnectionStrings and PathMappings copied from the production slot of the application.

How can I use the command such that the slot created does NOT have any settings copied?

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,237 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,212 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Marcin Policht 16,335 Reputation points MVP
    2024-06-14T11:28:17.4733333+00:00

    Try the following:

    # Variables
    $ResourceGroup = "<YourResourceGroup>"
    $ApplicationName = "<YourApplicationName>"
    $SlotName = "<YourSlotName>"
    # Create the slot
    New-AzWebAppSlot -ResourceGroupName $ResourceGroup -Name $ApplicationName -Slot $SlotName -ErrorAction Stop
    # Clear AppSettings
    $slotAppSettings = @{}
    Set-AzWebAppSlot -ResourceGroupName $ResourceGroup -Name $ApplicationName -Slot $SlotName -AppSettings $slotAppSettings
    # Clear ConnectionStrings
    $slotConnectionStrings = @{}
    Set-AzWebAppSlot -ResourceGroupName $ResourceGroup -Name $ApplicationName -Slot $SlotName -ConnectionStrings $slotConnectionStrings
    # Clear PathMappings (Virtual Applications and Directories)
    $slotPathMappings = @{}
    Set-AzWebAppSlot -ResourceGroupName $ResourceGroup -Name $ApplicationName -Slot $SlotName -VirtualApplications $slotPathMappings
    
    

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin