$switchName = 'nat-switch' $switchNetworkAdapterName = "vEthernet ($switchName)" $natGatewayIpAddress = '192.168.5.1' $natIpPrefixLength = 24 $natNetworkName = 'nat-network' $natNetworkInternalIPInterfaceAddressPrefix = '192.168.5.0/24' New-VMSwitch -SwitchName $switchName -SwitchType Internal Start-Sleep -Seconds 1 $newVirtualSwitch = Get-VMSwitch -Name $switchName $virtualSwitchNetworkAdapter = Get-NetAdapter -Name $switchNetworkAdapterName $newVirtualSwitchIfConfig = ($virtualSwitchNetworkAdapter).ifIndex New-NetIPAddress -IPAddress $natGatewayIpAddress -PrefixLength $natIpPrefixLength -InterfaceIndex $newVirtualSwitchIfConfig New-NetNat –Name $natNetworkName –InternalIPInterfaceAddressPrefix $natNetworkInternalIPInterfaceAddressPrefix