Add the ability to use the hyperv provider.
This commit is contained in:
32
HyperV/hyperv-create-nat-switch.ps1
Normal file
32
HyperV/hyperv-create-nat-switch.ps1
Normal file
@@ -0,0 +1,32 @@
|
||||
# See: https://www.petri.com/using-nat-virtual-switch-hyper-v
|
||||
|
||||
If ("NATSwitch" -in (Get-VMSwitch | Select-Object -ExpandProperty Name) -eq $FALSE) {
|
||||
'Creating Internal-only switch named "NATSwitch" on Windows Hyper-V host...'
|
||||
|
||||
New-VMSwitch -SwitchName "NATSwitch" -SwitchType Internal
|
||||
|
||||
New-NetIPAddress -IPAddress 192.168.38.1 -PrefixLength 24 -InterfaceAlias "vEthernet (NATSwitch)"
|
||||
|
||||
New-NetNAT -Name "NATNetwork" -InternalIPInterfaceAddressPrefix 192.168.38.0/24
|
||||
}
|
||||
else {
|
||||
'"NATSwitch" for static IP configuration already exists; skipping'
|
||||
}
|
||||
|
||||
If ("192.168.38.1" -in (Get-NetIPAddress | Select-Object -ExpandProperty IPAddress) -eq $FALSE) {
|
||||
'Registering new IP address 192.168.38.1 on Windows Hyper-V host...'
|
||||
|
||||
New-NetIPAddress -IPAddress 192.168.38.1 -PrefixLength 24 -InterfaceAlias "vEthernet (NATSwitch)"
|
||||
}
|
||||
else {
|
||||
'"192.168.38.1" for static IP configuration already registered; skipping'
|
||||
}
|
||||
|
||||
If ("192.168.38.0/24" -in (Get-NetNAT | Select-Object -ExpandProperty InternalIPInterfaceAddressPrefix) -eq $FALSE) {
|
||||
'Registering new NAT adapter for 192.168.38.0/24 on Windows Hyper-V host...'
|
||||
|
||||
New-NetNAT -Name "NATNetwork" -InternalIPInterfaceAddressPrefix 192.168.38.0/24
|
||||
}
|
||||
else {
|
||||
'"192.168.38.0/24" for static IP configuration already registered; skipping'
|
||||
}
|
||||
Reference in New Issue
Block a user