Created
October 13, 2016 01:33
-
-
Save marckean/c4a51d58e211a115bdb86c746c4db35b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Log into Azure ARM | |
Login-AzureRmAccount | |
### Choose subscription 'new' Azure | |
$subscription = (Get-AzureRmSubscription | Out-GridView -Title "Select the Azure subscription that you want to use ..." -PassThru).SubscriptionName | |
Select-AzureRmSubscription -SubscriptionName $subscription | |
Import-Module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureRM.Network\AzureRM.Network.psd1" | |
########################################################################## | |
############################# vNet ############################## | |
########################################################################## | |
$vNetRGName = "Show-vNet" | |
$location = "australiaeast" | |
### Create the Resource Group | |
cls | |
Write-Host "`n`tCreating the target resource group $vNetRGName (if it don't exist already)..." -ForegroundColor Cyan | |
#region | |
if(!(Get-AzureRmResourceGroup -Name $vNetRGName -Location $location -ErrorAction SilentlyContinue)){ | |
New-AzureRmResourceGroup -Name $vNetRGName -Location $location -Force} | |
#Virtual Network | |
$vNetName = "Demo-vNet" | |
$vNetPrefix = "10.123.0.0/16" # 10.123.0.1 -> 10.123.255.254 | |
$DMZSubnetName = "DMZ" | |
$DMZSubnetPrefix = "10.123.250.0/24" | |
$IntSubnetName = "Internal" | |
$IntSubnetPrefix = "10.123.10.0/24" | |
$GWSubnetName = "GatewaySubnet" | |
$GWSubnetPrefix = "10.123.2.0/28" | |
### Create Virtual Network | |
$DMZSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name $DMZSubnetName -AddressPrefix $DMZSubnetPrefix | |
$IntSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name $IntSubnetName -AddressPrefix $IntSubnetPrefix | |
$GWSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name $GWSubnetName -AddressPrefix $GWSubnetPrefix | |
$vnet = New-AzureRmVirtualNetwork -Name $vNetName -ResourceGroupName $vNetRGName -Location $location -AddressPrefix $vNetPrefix -Subnet $DMZSubnet,$IntSubnet,$GWSubnet | |
########################################################################## | |
############################# VPN ############################## | |
########################################################################## | |
### Create vNet Gateway | |
### Create the Resource Group | |
$LocalSite = "SoftLayer" | |
$GWIPName = "Demo-GWIP" | |
$gwipconfig = "Demo-GWIPName" | |
$vnetgwName = "Demo-vNetGW" | |
$VPNconnection = "LocalToVPN" | |
$SharedKey = "4wer64erh0js35u4689" | |
$GatewayIpAddress = '168.1.113.85' | |
$AddressPrefix = '192.168.111.0/24' | |
New-AzureRmLocalNetworkGateway -Name $LocalSite -ResourceGroupName $vNetRGName -Location $location -GatewayIpAddress $GatewayIpAddress -AddressPrefix $AddressPrefix # @('10.0.0.0/24','20.0.0.0/24') | |
$gwpip = New-AzureRmPublicIpAddress -Name $GWIPName -ResourceGroupName $vNetRGName -Location $location -AllocationMethod Dynamic | |
$vnet = Get-AzureRmVirtualNetwork -Name $vNetName -ResourceGroupName $vNetRGName | |
$subnet = Get-AzureRmVirtualNetworkSubnetConfig -Name $GWSubnetName -VirtualNetwork $vnet | |
$gwipconfig = New-AzureRmVirtualNetworkGatewayIpConfig -Name $gwipconfig -SubnetId $subnet.Id -PublicIpAddressId $gwpip.Id | |
### Create the vNet Gateway | |
New-AzureRmVirtualNetworkGateway -Name $vnetgwName -ResourceGroupName $vNetRGName -Location $location -IpConfigurations $gwipconfig -GatewayType Vpn -VpnType RouteBased -GatewaySku Standard | |
########################################################################## | |
############################# Connection ############################# | |
########################################################################## | |
### Create the Connection | |
$gateway = Get-AzureRmVirtualNetworkGateway -Name $vnetgwName -ResourceGroupName $vNetRGName | |
$local = Get-AzureRmLocalNetworkGateway -Name $LocalSite -ResourceGroupName $vNetRGName | |
New-AzureRmVirtualNetworkGatewayConnection -Name $VPNconnection -ResourceGroupName $vNetRGName -Location $location -VirtualNetworkGateway1 $gateway -LocalNetworkGateway2 $local -ConnectionType IPsec -RoutingWeight 10 -SharedKey $SharedKey | |
# https://azure.microsoft.com/en-us/documentation/articles/vpn-gateway-about-vpn-devices/ | |
$local = Get-AzureRmLocalNetworkGateway -Name LocalSite -ResourceGroupName testrg | |
Set-AzureRmLocalNetworkGateway -LocalNetworkGateway $local -AddressPrefix @('192.168.111.0/24') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment