Before creating a virtual network, you have to create a resource group for the virtual network, and all other resources created in this article. Create a resource group with New-AzResourceGroup. The following example creates a resource group named test-rg in the eastus location.
$resourceGroup = @{
Name = "test-rg"
Location = "EastUS2"
}
New-AzResourceGroup @resourceGroup
Create a virtual network with New-AzVirtualNetwork. The following example creates a virtual network named vnet-1 with the address prefix 10.0.0.0/16.
$vnet1 = @{
ResourceGroupName = "test-rg"
Location = "EastUS2"
Name = "vnet-1"
AddressPrefix = "10.0.0.0/16"
}
$virtualNetwork1 = New-AzVirtualNetwork @vnet1
Create a subnet configuration with Add-AzVirtualNetworkSubnetConfig. The following example creates a subnet configuration with a 10.0.0.0/24 address prefix:
$subConfig = @{
Name = "subnet-1"
AddressPrefix = "10.0.0.0/24"
VirtualNetwork = $virtualNetwork1
}
$subnetConfig1 = Add-AzVirtualNetworkSubnetConfig @subConfig
Create a subnet configuration for Azure Bastion with Add-AzVirtualNetworkSubnetConfig. The following example creates a subnet configuration with a 10.0.1.0/24 address prefix:
$subBConfig = @{
Name = "AzureBastionSubnet"
AddressPrefix = "10.0.1.0/24"
VirtualNetwork = $virtualNetwork1
}
$subnetConfig2 = Add-AzVirtualNetworkSubnetConfig @subBConfig
Write the subnet configuration to the virtual network with Set-AzVirtualNetwork, which creates the subnet:
$virtualNetwork1 | Set-AzVirtualNetwork
Create Azure Bastion
Create a public IP address for the Azure Bastion host with New-AzPublicIpAddress. The following example creates a public IP address named public-ip-bastion in the vnet-1 virtual network.
$publicIpParams = @{
ResourceGroupName = "test-rg"
Name = "public-ip-bastion"
Location = "EastUS2"
AllocationMethod = "Static"
Sku = "Standard"
}
New-AzPublicIpAddress @publicIpParams
Create an Azure Bastion host with New-AzBastion. The following example creates an Azure Bastion host named bastion in the AzureBastionSubnet subnet of the vnet-1 virtual network. Azure Bastion is used to securely connect Azure virtual machines without exposing them to the public internet.
$bastionParams = @{
ResourceGroupName = "test-rg"
Name = "bastion"
VirtualNetworkName = "vnet-1"
PublicIpAddressName = "public-ip-bastion"
PublicIpAddressRgName = "test-rg"
VirtualNetworkRgName = "test-rg"
}
New-AzBastion @bastionParams -AsJob