使用 powershell 或 azure cli 为多个 Azure webapp 插槽添加 vnet 集成

Adding vnet integration for the multiple Azure webapp slots using powershell or azure cli

我正在尝试使用 powershell 将多个 Web 应用程序和插槽集成到 Vnet 中。为 webapps 启用 vnet 集成的地方工作正常,但以同样的方式为 webapp slots 它不起作用。

$RGName = "web app resource group name "
$vnetName = "yashvnet01"
$VnetRG = "vnet name"
$subnetName = "subnet name"

$Vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $VnetRG
$subnet = Get-AzVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $Vnet

$Vnet.Id

##Add vnet integration to the webapps in the specific Resource group
$Webapps=Get-AzWebApp -ResourceGroupName $RGname
$Webapps.Name

ForEach($webapp in $Webapps.Name)
{
Write-Host "Adding Vnet intergation to the $webapp"

az webapp vnet-integration add --resource-group $RGname --name $webapp --vnet $Vnet.Id --subnet $subnetName

Write-Host "Successfully added Vnet intergation to the $webapp"
}


我们如何为多个 webapp 插槽做同样的事情。

如果有人能帮助我,我会很高兴。

干杯 热文

您可以使用以下脚本在 webapps 插槽上应用 v-net 集成。

Connect-AzAccount

$RGName = "yourresourcegroupname"
$vnetName = "vnetname"
$VnetRG = "vnet resource group name"
$subnetName = "subnetname"

$Vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $VnetRG
$subnet = Get-AzVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $Vnet

$Vnet.Id

$Webapps=Get-AzWebApp -ResourceGroupName $RGname
$Webapps.Name

##Add vnet integration to the webapps slots in the specific Resource group

ForEach($webapp in $Webapps.Name)
{
#Webapp slot
$WebappsSlot = Get-AzWebAppSlot -ResourceGroupName $RGName -Name $webapp
$WebappsSlot.Name

ForEach($webappSlot in $WebappsSlot.Name) {

$s = $webappSlot -replace $webapp + "/"

Write-Host "Adding Vnet intergation to the $s"

az webapp vnet-integration add --resource-group $RGname --name $webapp --vnet $Vnet.Id --subnet $subnetName -s $s

Write-Host "Successfully added Vnet intergation to the $s"
}
}

测试输出:

注:

请确保在 运行 以上代码时使用更新的 az 版本。上面使用的 az cli 版本是 2.71.1 。您可以在 powershell 中使用命令 az upgrade 升级 az 版本。