-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_NAT_adapter.ps1
More file actions
25 lines (19 loc) · 916 Bytes
/
create_NAT_adapter.ps1
File metadata and controls
25 lines (19 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$switchName = "nat"
$natName = "nat"
$adapterIP = "192.168.100.1"
$prefixLength = 24
$subnetPrefix = "192.168.100.0/24"
Write-Output "Be sure to check your system's IP configuration. Default is 192.168.... some systems may need 172.16... ect"
# create internal virtual switch
New-VMSwitch -Name $switchName -SwitchType Internal
# find adapter associated with virtual switch
$adapter = Get-NetAdapter | Where-Object { $_.Name -like "vEthernet ($switchName)" }
if ($null -eq $adapter) {
Write-Output "vEthernet adapter for switch '$switchName' not found."
exit
}
# assign the IP address
New-NetIPAddress -InterfaceAlias $adapter.Name -IPAddress $adapterIP -PrefixLength $prefixLength
# create a NAT network
New-NetNat -Name $natName -InternalIPInterfaceAddressPrefix $subnetPrefix
Write-Output "vEthernet adapter '$adapter.Name' created. IP $adapterIP assigned and NAT network '$natName' configured."