Skip to content

Instantly share code, notes, and snippets.

@afalahi
Created September 21, 2018 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afalahi/f1f2218eb71b830053b1f8242da3ab56 to your computer and use it in GitHub Desktop.
Save afalahi/f1f2218eb71b830053b1f8242da3ab56 to your computer and use it in GitHub Desktop.
create-nat-switch
$VerbosePreference = "Continue"
Write-Verbose -Message "Creating the VM Switch"
$SwitchName=Read-Host "Switch Name"
New-VMSwitch -Name "$SwitchName" -SwitchType Internal
Write-Verbose -Message "Switch Created Successfully"
Write-Verbose -Message "Assiging IP and SubnetMask to $SwitchName"
$GateWay= Read-Host "Enter Gatway Address"
$prefixLength = 24
$ifIndex = Get-NetAdapter | Where {$_.Name -like "*$SwitchName*"}
New-NetIPAddress -IPAddress $GateWay -PrefixLength $prefixLength -InterfaceIndex $ifIndex.ifIndex
Write-Verbose -Message "IP Address $GateWay Assigned With Success to $SwitchName"
Write-Verbose -Message "Creating NAT Network"
$NatName=Read-Host "Enter Nat Name"
$NatSubnet=Read-Host "Enter Nat Subnet example 192.168.0.0/24 must match your Gatway range/class"
Write-Verbose -Message "Creating NAT $NatName with $NatSubnet"
New-NetNat -Name "$NatName" -InternalIPInterfaceAddressPrefix "$NatSubnet"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment