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
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
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
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
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.
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
Thanks guys, i will check this