简体   繁体   English

如何在预先存在的 Vnet Powershell 中创建多个子网

[英]How to create multiple Subnets in pre-existing Vnet Powershell

I have the following code which works good for adding a few subnets but I would like for this script to leverage a CSV file to import from and add the subnets into a pre-existing Vnet?我有以下代码可以很好地添加一些子网,但我希望此脚本利用 CSV 文件从预先存在的 Vnet 导入子网并将其添加到预先存在的 Vnet 中?



$appssubnet = New-AzVirtualNetworkSubnetConfig -Name servers -AddressPrefix "172.16.1.0/24" -NetworkSecurityGroupId "/subscriptions/xxxxxxxxxx-xxxx-xxxx-xxxxx-xxxxxxxxxxxx/resourceGroups/powershell-grp/providers/Microsoft.Network/networkSecurityGroups/app-nsg1"`
-RouteTableId "/subscriptions/xxxxxxxxxx-xxxx-xxxx-xxxxx-xxxxxxxxxxxx/resourceGroups/powershell-grp/providers/Microsoft.Network/routeTables/powershell-rt"
$serversubnet = New-AzVirtualNetworkSubnetConfig -Name apps -AddressPrefix "172.16.2.0/24" -RouteTableId "/subscriptions/xxxxxxxxxx-xxxx-xxxx-xxxxx-xxxxxxxxxxxx/resourceGroups/powershell-grp/providers/Microsoft.Network/routeTables/powershell-rt"
$dmz = New-AzVirtualNetworkSubnetConfig -Name dmz -AddressPrefix "172.16.3.0/24"
$updatedvnet = New-AzVirtualNetwork -Name "testsubnet" -ResourceGroupName "powershell-grp" -Location "North Europe" -AddressPrefix "172.16.0.0/16" -Subnet $serversubnet, $dmz, $appssubnet -Force:$true
$updatedvnet | Set-AzVirtualNetwork


You can use the below powershell script.您可以使用以下 powershell 脚本。

  $subnets1 = Import-Csv "C:\Users\v-XXXsXX18\Documents\TestCount.csv"
    #$subnets1.subnetName
    foreach ($subnet in $subnets1){
    $dmz = New-AzVirtualNetworkSubnetConfig -Name $subnet.SubnetName -AddressPrefix $subnet.AddressPrefix
    
    $vnet=Get-AzVirtualNetwork -Name "MyVirtualNetworkTes" -ResourceGroupName "v-raXXXXndtree"
    $updatedvnet=Add-AzVirtualNetworkSubnetConfig -Name $dmz.Name -VirtualNetwork $vnet -AddressPrefix $dmz.AddressPrefix
    
    $updatedvnet | Set-AzVirtualNetwork
    
    
    }

在此处输入图像描述

Output--输出 -

在此处输入图像描述

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure在具有多个子网的现有VNET上创建VM - Azure creating VM on existing VNET with multiple subnets 无法使用现有 VNET 和子网创建 Azure AKS 群集 - Unable to create Azure AKS Cluster using existing VNET and Subnets 使用 Terrafrom 的同一 VNet 中的多个子网 - Multiple subnets in same VNet with Terrafrom 使用 PowerShell 和现有 VNET 创建 Azure VM - Create an Azure VM using PowerShell with an existing VNET 通过ARM模板将子网添加到现有Vnet - Addition of subnets to existing Vnet through ARM templates ARM 模板,用于与现有 VNET 子网集成的 Appservice - ARM template for Appservice integrating with existing VNET Subnets 如何使用PowerShell的ARM模板将Azure WebApp创建到现有v1 VNet? - How to create Azure WebApp to an existing v1 VNet using ARM templates of PowerShell? 如何在现有的Vnet中创建子网 - How do I create Subnet in existing Vnet 在不影响现有子网的情况下将 Azure VPN 网关部署到现有 vnet - Deploy Azure VPN gateway to existing vnet without affecting existing subnets 如何使用二头肌在 azure eventHub 的网络部分中选择和添加 VNet 的多个子网 - How to select and add multiple subnets of a VNet in networking section of an azure eventHub using bicep
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM