Created
September 21, 2018 18:42
-
-
Save afalahi/f1f2218eb71b830053b1f8242da3ab56 to your computer and use it in GitHub Desktop.
create-nat-switch
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
$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