Skip to content

Instantly share code, notes, and snippets.

@CallMarl
Last active September 26, 2020 14:16
Show Gist options
  • Save CallMarl/0f816ff9b55287a537f538bb212f28fa to your computer and use it in GitHub Desktop.
Save CallMarl/0f816ff9b55287a537f538bb212f28fa to your computer and use it in GitHub Desktop.
Powershell Network Management
# Run powershell as administrator
# Create powershell internal interface. This is to create the first VMs Cluster Gateway
New-VMSwitch –SwitchName “Cluster_VMs_1” –SwitchType Internal –Verbose
# Find the new interface index (it's the value in the ifindex column)
Get-NetAdapter -Name "vEthernet (Cluster_VMs_1)"
# Set up the ip address of the interface, this address will be the gateway of the nat network. (192.168.2.0/24)
# In my case the interface index value is 45.
New-NetIPAddress –IPAddress 192.168.2.1 -PrefixLength 24 -InterfaceIndex 45 –Verbose
# Then create the net-network for the first cluster of VMs
New-NetNat -Name "NetNat_VMs_1" -InternalIPInterfaceAddressPrefix 192.168.2.0/24 -Verbose
# In windows the nat network always use the 1 network address as gateway in this exemple 192.168.2.1
# To display helping info about netsh
# PS C:\Users\CallMarl> netsh
# netsh>/?
# Display forwarding rules
netsh interface portproxy show all
# Create forward rule between loopback interface then Cluster_VM_1 interface
netsh interface portproxy add v4tov4 listenaddress=127.0.0.1 listenport=8080 connectaddress=192.168.2.2 connectport=80
# Delete forward rule
netsh interface portproxy delete v4tov4 listenaddress=127.0.0.1 listenport=8080
# List the current adapter of the systeme
Get-NetAdapter
# List the current adapter of the systeme included hidden
Get-NetAdapter -IncludeHidden
# Display virtual net adapter
Get-VMSwitch
# Create Virtual net adapter
# There 3 SwitchType: External, Internal, Privare
New-VMSwitch –SwitchName "my-Switch-name" –SwitchType External –Verbose
# Remove virtual net adapter
Remove-VmSwitch -name "my-Switch-name"
# Get all interfaces detail
Get-NetIpAddress
# Get specific interface detail
Get-NetIpAddress -InterfaceAlias "Wi-Fi" -AddressFamily IPv4
# Create address ip for fresh creating interface
New-NetIPAddress –IPAddress 192.168.2.1 -PrefixLength 24 -InterfaceIndex 16 –Verbose
# Get nat network information
Get-NetNat
# Get specific nat network information
Get-NetNat -name "my-nat-network"
# Create nat network
New-NetNat –Name "my-nat-network" –InternalIPInterfaceAddressPrefix 192.168.2.0/24 –Verbose
# Get network categories for each interfaces
Get-netConnectionProfile
# Set network connextion to private
Set-NetConnectionProfile -InterfaceAlias "Wi-Fi" -NetworkCategory private
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment