VMware Cloud Community
olan025
Enthusiast
Enthusiast

using set-virtualswitch to add a vmnic

I am working to add a nic to an existing virtual switch. I can add them at creation time, yet apparently calling set-virtualswitch seperately is not my thing.

Adding vmnic2 to vSwitch1 in this case

$vs = get-virtualswitch -name vSwitch1

$nics= get-vmhost $vmhost | get-vmhostnetwork | %{$_.physicalnic} | where {$_.DeviceName -like "vmnic2"}

set-virtualswitch -VirtualSwitch $vs -Nic $nics

I get

""

Set-Virtual Switch The object or item referred to could not be found. At line 6, position 18 which is where I call the "-VirtualSwitch" parameter. IT seems that this parameter is not recognized or my value is not what it wants..

The get-help set-virtualswitch -full page uses this parameter, so I am thinking my value is incorrect.

0 Kudos
4 Replies
LucD
Leadership
Leadership

Try this

$vs = Get-VirtualSwitch -Name <vswitch-name> -VMHost (Get-VMHost <ESX-hostname>)
Set-VirtualSwitch -VirtualSwitch $vs -Nic <NIC-name>

That should do the trick.


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

0 Kudos
olan025
Enthusiast
Enthusiast

$vmhost = Read-Host "Enter DNS Name for Host"

connect-viserver $vmhost -user &lt;user&gt; -password &lt;password&gt;

$nic = get-vmhost $vmhost | get-vmhostnetwork | %{$_.physicalnic}| where { $_.DeviceName -like "vmnic2"}

get-virtualswitch -name vSwitch1 -vmhost (get-vmhost $vmhost) | Set-Virtualswitch -Virtualswitch $vs -nic $nic

Here's my commands and it errors out

The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.

At line 6, position 171

get-virtualswitch -name vSwitch1 -vmhost (get-vmhost $vmhost) | Set-Virtualswitch -Virtualswitch $vs -nic $nic

I'm passing it the $nic which it errors out on. So I'm wondering now if I have another issue grabbing the required info for the -Nic variable.

Did you get that command to run on an environment?

Thanks for assisting

0 Kudos
LucD
Leadership
Leadership

Yes, just tried it in our test environment.

Could you give it a try with actual values instead of variables ?

And you are on build 103777 ? Do a Get-VIToolkitVersion to make sure.


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

0 Kudos
olan025
Enthusiast
Enthusiast

LucD,

Running it in command worked fine as you put. I'll have to dig into what I was hosing up. I'm sure I was passing the incorrect object or array.

I am on 103777.

Thanks again!

0 Kudos