你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

New-AzVirtualNetworkSubnetConfig

创建虚拟网络子网配置。

语法

SetByResource (默认值)

New-AzVirtualNetworkSubnetConfig
    -Name <String>
    [-AddressPrefix <String[]>]
    [-IpamPoolPrefixAllocation <PSIpamPoolPrefixAllocation[]>]
    [-NetworkSecurityGroup <PSNetworkSecurityGroup>]
    [-RouteTable <PSRouteTable>]
    [-InputObject <PSNatGateway>]
    [-ServiceEndpoint <String[]>]
    [-NetworkIdentifier <PSResourceId>]
    [-ServiceEndpointConfig <PSServiceEndpoint[]>]
    [-ServiceEndpointPolicy <PSServiceEndpointPolicy[]>]
    [-Delegation <PSDelegation[]>]
    [-PrivateEndpointNetworkPoliciesFlag <String>]
    [-PrivateLinkServiceNetworkPoliciesFlag <String>]
    [-IpAllocation <PSIpAllocation[]>]
    [-DefaultOutboundAccess <Boolean>]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

SetByResourceId

New-AzVirtualNetworkSubnetConfig
    -Name <String>
    [-AddressPrefix <String[]>]
    [-IpamPoolPrefixAllocation <PSIpamPoolPrefixAllocation[]>]
    [-NetworkSecurityGroupId <String>]
    [-RouteTableId <String>]
    [-ResourceId <String>]
    [-ServiceEndpoint <String[]>]
    [-NetworkIdentifier <PSResourceId>]
    [-ServiceEndpointConfig <PSServiceEndpoint[]>]
    [-ServiceEndpointPolicy <PSServiceEndpointPolicy[]>]
    [-Delegation <PSDelegation[]>]
    [-PrivateEndpointNetworkPoliciesFlag <String>]
    [-PrivateLinkServiceNetworkPoliciesFlag <String>]
    [-IpAllocation <PSIpAllocation[]>]
    [-DefaultOutboundAccess <Boolean>]
    [-DefaultProfile <IAzureContextContainer>]
    [<CommonParameters>]

说明

New-AzVirtualNetworkSubnetConfig cmdlet 创建虚拟网络子网配置。

示例

示例 1:创建包含两个子网和网络安全组的虚拟网络

New-AzResourceGroup -Name TestResourceGroup -Location centralus

$rdpRule = New-AzNetworkSecurityRuleConfig -Name rdp-rule -Description "Allow RDP" `
   -Access Allow -Protocol Tcp -Direction Inbound -Priority 100 `
   -SourceAddressPrefix Internet -SourcePortRange * `
   -DestinationAddressPrefix * -DestinationPortRange 3389

$networkSecurityGroup = New-AzNetworkSecurityGroup -ResourceGroupName TestResourceGroup `
  -Location centralus -Name "NSG-FrontEnd" -SecurityRules $rdpRule

$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name frontendSubnet `
    -AddressPrefix "10.0.1.0/24" -NetworkSecurityGroup $networkSecurityGroup

$backendSubnet = New-AzVirtualNetworkSubnetConfig -Name backendSubnet `
    -AddressPrefix "10.0.2.0/24" -NetworkSecurityGroup $networkSecurityGroup

$pip = New-AzPublicIpAddress -Name "pip" -ResourceGroupName "natgateway_test" `
   -Location "eastus2" -Sku "Standard" -IdleTimeoutInMinutes 4 -AllocationMethod "static"

$natgateway = New-AzNatGateway -ResourceGroupName "natgateway_test" -Name "nat_gateway" `
   -IdleTimeoutInMinutes 4 -Sku "Standard" -Location "eastus2" -PublicIpAddress $pip

$natGatewaySubnet = New-AzVirtualNetworkSubnetConfig -Name natGatewaySubnet `
   -AddressPrefix "10.0.3.0/24" -InputObject $natGateway

New-AzVirtualNetwork -Name MyVirtualNetwork -ResourceGroupName TestResourceGroup `
    -Location centralus -AddressPrefix "10.0.0.0/16" -Subnet $frontendSubnet,$backendSubnet,$natGatewaySubnet

此示例使用 New-AzVirtualNetworkSubnetConfig cmdlet 创建两个新子网配置,然后使用它们创建虚拟网络。 New-AzVirtualNetworkSubnetConfig 模板仅创建子网的内存中表示形式。 在此示例中,frontendSubnet 具有 CIDR 10.0.1.0/24,并引用允许 RDP 访问的网络安全组。 backendSubnet 具有 CIDR 10.0.2.0/24,并引用相同的网络安全组。

参数

-AddressPrefix

指定子网配置的 IP 地址范围。

参数属性

类型:

String[]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-DefaultOutboundAccess

子网中所有 VM 的默认出站连接

参数属性

类型:

Nullable<T>[Boolean]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-DefaultProfile

用于与 Azure 通信的凭据、帐户、租户和订阅。

参数属性

类型:IAzureContextContainer
默认值:None
支持通配符:False
不显示:False
别名:AzContext, AzureRmContext, AzureCredential

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Delegation

有权在此子网上执行作的服务列表。

参数属性

类型:

PSDelegation[]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-InputObject

指定与子网配置关联的 nat 网关

参数属性

类型:PSNatGateway
默认值:None
支持通配符:False
不显示:False
别名:NatGateway 网关

参数集

SetByResource
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-IpAllocation

指定子网的 IpAllocations。

参数属性

类型:

PSIpAllocation[]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-IpamPoolPrefixAllocation

从 IpamPool 自动分配子网地址前缀。

参数属性

类型:

PSIpamPoolPrefixAllocation[]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Name

指定要创建的子网配置的名称。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:True
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-NetworkIdentifier

ServiceEndpoint 的 NetworkIdentifier 值

参数属性

类型:PSResourceId
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-NetworkSecurityGroup

指定 NetworkSecurityGroup 对象。

参数属性

类型:PSNetworkSecurityGroup
默认值:None
支持通配符:False
不显示:False

参数集

SetByResource
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-NetworkSecurityGroupId

指定网络安全组的 ID。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

SetByResourceId
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-PrivateEndpointNetworkPoliciesFlag

配置为启用或禁用在子网中的专用终结点上应用网络策略。 默认值为 Disabled。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-PrivateLinkServiceNetworkPoliciesFlag

配置为启用或禁用在子网中的专用链接服务上应用网络策略。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-ResourceId

指定与子网配置关联的 NAT 网关资源的 ID。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False
别名:NatGatewayId

参数集

SetByResourceId
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-RouteTable

指定与子网配置关联的路由表。

参数属性

类型:PSRouteTable
默认值:None
支持通配符:False
不显示:False

参数集

SetByResource
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-RouteTableId

指定与子网配置关联的路由表的 ID。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

SetByResourceId
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-ServiceEndpoint

服务终结点值

参数属性

类型:

String[]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-ServiceEndpointConfig

具有 NetworkIdentifier 值的服务终结点

参数属性

类型:

PSServiceEndpoint[]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

-ServiceEndpointPolicy

服务终结点策略

参数属性

类型:

PSServiceEndpointPolicy[]

默认值:None
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):True
来自剩余参数的值:False

CommonParameters

此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters

输入

String

PSNetworkSecurityGroup

PSRouteTable

PSNatGateway

String

PSServiceEndpointPolicy

PSDelegation

输出

PSSubnet