Add Virtual Directory to an Azure Website using Powershell Add Virtual Directory to an Azure Website using Powershell powershell powershell

Add Virtual Directory to an Azure Website using Powershell


Looks like a valid (if somewhat complex) answer here:

The short of it is: You gotta use AzureResourceManager and work with a Microsoft.web/sites/config object to get and set Virtual Directories.

https://social.msdn.microsoft.com/Forums/azure/en-US/990f41fd-f8b6-43a0-b942-cef0308120b2/add-virtual-application-and-directory-to-an-azure-website-using-powershell?forum=windowsazurewebsitespreview


I've just been struggling to do this recently, and found a simpler solution here:

 $website = Get-AzureRmWebApp -Name "myWebApp" -ResourceGroupName "myResourceGroup"  $VDApp = New-Object Microsoft.Azure.Management.WebSites.Models.VirtualApplication  $VDApp.VirtualPath = "/TEST"  $VDApp.PhysicalPath = "site\\TEST"  $VDApp.PreloadEnabled ="YES"  $website.siteconfig.VirtualApplications.Add($VDApp)  $website | Set-azureRmWebApp 


Based on Ben's answer:

$props = @{    "virtualApplications" = @(        @{            "virtualPath"  = "/";            "physicalPath" = "site\wwwroot";        },        @{            "virtualPath"  = "/SOME_VIRTUAL_PATH";            "physicalPath" = "site\wwwroot";        }    )}Set-AzureRmResource `    -ResourceGroupName $resourceGroupName `    -ResourceType "Microsoft.Web/sites/config" `    -ResourceName "$appServiceName/web" `    -PropertyObject $props `    -ApiVersion "2015-08-01" `    -Force