Powershell中的Set-AzureRmWebApp更改未显示在Azure门户中

时间:2017-08-28 16:29:26

标签: azure azure-web-sites azure-powershell

我正在尝试通过Powershell将虚拟应用程序添加到Azure网站。虽然脚本运行没有错误,但我的更改不会出现在portal.azure.com中。还有另一个命令我需要在最后运行以保持更改吗?

$subscriptionId = "secret"
$websiteName = "MyWebsite"
$resourceGroupName = "MyResourceGroup"
$siteName = "Test"

Get-Module AzureRM
Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionId $subscriptionId
$website = Get-AzureRmWebApp -Name $websiteName -ResourceGroupName $resourceGroupName
$VDApp = New-Object Microsoft.Azure.Management.WebSites.Models.VirtualApplication
$VDApp.VirtualPath = "/$siteName"
$VDApp.PhysicalPath = "site\$siteName"
$VDApp.PreloadEnabled ="YES"
$website.siteconfig.VirtualApplications.Add($VDApp)
$website | Set-AzureRmWebApp -ResourceGroupName $resourceGroupName

2 个答案:

答案 0 :(得分:0)

尝试使用以下命令添加虚拟应用程序。

$resourceGroupName = ""
$websiteName = ""
$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

我在实验室测试,它对我有用。

enter image description here

有关此内容的详情,请参阅herehere

答案 1 :(得分:0)

使用沃尔特的答案作为基础。要将新虚拟应用程序附加到现有虚拟应用程序,请运行以下代码:

# Example call: SetWebAppConfig MyResourceGroup MySite $ConfigObject
# https://github.com/davidebbo/AzureWebsitesSamples/blob/b2a3d67a90b7b2d673d68dab553f82e015333d10/PowerShell/HelperFunctions.ps1#L84-L87
Function SetWebAppConfig($ResourceGroupName, $SiteName, $ConfigObject)
{
    $WebAppApiVersion = "2015-08-01"
    Set-AzureRmResource -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.Web/sites/Config -Name $SiteName/web -PropertyObject $ConfigObject -ApiVersion $WebAppApiVersion -Force
}

Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionId $subscriptionId

$website = Get-AzureRmWebApp -ResourceGroupName $resourceGroupName -Name $websiteName
$virtualApplications = $website.SiteConfig.VirtualApplications

$hash = New-Object System.Collections.ArrayList

for ($j = 0; $j -lt $virtualApplications.count; $j++) {
    $entry = @{ virtualPath = $virtualApplications[$j].VirtualPath; physicalPath = $virtualApplications[$j].PhysicalPath }
    $hash.add($entry)
}
$newEntry = @{ virtualPath = "/$siteName"; physicalPath = "site\$siteName" }
$hash.add($newEntry)


$hashProps.VirtualApplications
$virtualApps = $website.SiteConfig.VirtualApplications.Add(@{ virtualPath = "/$siteName"; physicalPath = "site\$siteName" })
$props=@{
    virtualApplications = $hash.ToArray()
}

SetWebAppConfig $resourceGroupName $websiteName $props