Bastiaan Schenk
Bastiaan Schenk

Reputation: 11

Remove a virtual application/directory form a webapp in Azure - powershell

There are a lot of items about adding a virtual application/directory to a webapp using powershell which works perfectly.

Now i'm looking for something to delete a virtual application/directory from a webapp using powershell

I've searched the Azure API docs and can't find anything about this. Can anyone help me with this?

Upvotes: 1

Views: 666

Answers (1)

AmanGarg-MSFT
AmanGarg-MSFT

Reputation: 1153

In order to add/delete a virtual directory/application please follow the below steps:

Initially you would have something like this:

enter image description here

  1. To add a virtual application:
    $resourceGroupName = "myResourceGroup"
    $websiteName = "myWebApp"
    $WebAppApiVersion = "2015-08-01"
    # Example call: SetWebAppConfig MyResourceGroup MySite $ConfigObject
    Function SetWebAppConfig($ResourceGroupName, $websiteName, $ConfigObject)
    {
        Set-AzureRmResource -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.Web/sites/Config -Name $websiteName/web -PropertyObject $ConfigObject -ApiVersion $WebAppApiVersion -Force
    }
    Write-Host "Set a virtual application"
    $props=@{
        virtualApplications = @(
            @{ virtualPath = "/"; physicalPath = "site\wwwroot" },
            @{ virtualPath = "/bar"; physicalPath = "site\wwwroot" }
        )
    }
    SetWebAppConfig $ResourceGroupName $websiteName $props

A virtual application got added:

enter image description here

  1. To add a virtual directory:
    $props=@{
        virtualApplications = @(
            @{ virtualPath = "/"; physicalPath = "site\wwwroot" },
            @{ virtualPath = "/bar"; physicalPath = "site\wwwroot"; virtualDirectories = @( @{virtualPath = "/images"; physicalPath = "site\wwwroot\images"}) }
        )
    }
    SetWebAppConfig $ResourceGroupName $websiteName $props

A virtual directory got added:

enter image description here

  1. To delete the virtual directory:
    $props=@{
        virtualApplications = @(
            @{ virtualPath = "/"; physicalPath = "site\wwwroot" },
            @{ virtualPath = "/bar"; physicalPath = "site\wwwroot"; virtualDirectories = $null }
        )
    }
    SetWebAppConfig $ResourceGroupName $websiteName $props

The virtual directory will be deleted:

enter image description here

  1. To delete the virtual application:
    $props=@{
        virtualApplications = @(
            @{ virtualPath = "/"; physicalPath = "site\wwwroot" }
        )
    }
    SetWebAppConfig $ResourceGroupName $websiteName $props

The virtual application will be deleted:

enter image description here

Things to note:

  • There is no way to fetch the existing virtual applications and directories.
  • Set-AzureRmResource will replace the existing PropertyObject with the provided PropertyObject.

Hope this helps!

Upvotes: 1

Related Questions