VMware Cloud Community
johnlennon
Enthusiast
Enthusiast
Jump to solution

How to change NIC settings with Set-VMHostNetworkAdapter

How do I use Set-VMHostNetworkAdapter to set the link speed and duplex mode of a give NIC of a server?

This doesn't work:

$myhost | Set-VMHostNetworkAdapter -PhysicalNic vmnic0 -Duplex "Full" -BitRatePerSecMb 100

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Insert a Where-Object in the pipe and you could filter for example on the physical NIC name.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
5 Replies
olan025
Enthusiast
Enthusiast
Jump to solution

Wow the Beattles are into Powershell? I got this from a colleage when working through my new ESXi config scripts.

$physnics = get-vmhost <vmhost> | get-vmhostnetwork | % {$_.Physicalnic}

set-vmhostnetworkadapter -PhysicalNic $physnics -BitRatePerSecMB <bitrate> -Duplex <duplex>

I then sleep for 5 seconds with

start-sleep -s 5

then send a reconnect - if you're doing all nics, you'll be doing the NIC that your attaching to for running the script. Some environments flip duplex quicker so you may have to adjust the seconds.

Message was edited by: olan025

To do a specific one... Add this following the first line starting with the pipe........... | where { $_.DeviceName -like "vmnic0"}

$physnics= get-vmhost <vmhost> | get-vmhostnetwork | %{$_.physicalnic}| where { $_.DeviceName -like "vmnic0"}

set-vmhostnetworkadapter -PhysicalNic $physnics -BitRatePerSecMB 1000 -Duplex full

LucD
Leadership
Leadership
Jump to solution

That cmdlet only works when you are connected to an ESX server.

So first do

Connect-VIServer -Server <ESX-server> -User <account> -Password <password>

You should notice that the variable $DefaultVIServer now contains the ESX server to which you just connected.

The Set-VMHostNetworkAdapter cmdlet expects an object of the type VMware.VimAutomation.Types.Host.NIC.PhysicalNic with the -PhysicalNic parameter.

You can get at these with the following

Get-VMHostNetwork | Select PhysicalNic

And now, finallly, you use the Set-VMHostNetworkAdapter cmdlet to change link speed and duplex mode

Get-VMHostNetwork | Select PhysicalNic | Set-VMHostNetworkAdapter -Duplex "Full" -BitRatePerSecMb 100


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

johnlennon
Enthusiast
Enthusiast
Jump to solution

thank you both for the quick answer. Is it possible to select which NICs to operate on? There is one I don't need to update, the rest I do.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Insert a Where-Object in the pipe and you could filter for example on the physical NIC name.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
sachink0312
Enthusiast
Enthusiast
Jump to solution

Thanks guys, i will check this

Sachin
0 Kudos