Add a vSwitch, PowerCLI vs. vCLI

In trying to get used to ESXi and it’s console-less nature I’ve been forcing myself to use the vCLI or PowerCLI to do things. Along the way I’ve learned that the vCLI is generally really well though out, if different. Here is an example of this: Setting up a vNetwork Standard Switch (vSwitch) using PowerCLI and the vCLI:

PowerCLI

    Steps:

  1. Connect to the ESXi or vCenter server:
    Get-Credential | Connect-VIServer –Server 1.2.3.4
  2. Create the new vSwitch:
    Get-VMHost –Name “ESX Host” | New-VirtualSwitch –Name “NewSwitch”

A very basic example that, no uplinks and the like, but it does show that the action is very straight forward in PowerCLI.

vCLI

This one is actually much much more complicated than the above (not really, but well…)

vicfg-vswitch.pl –add vSwitch1 –server 1.2.3.4 –username root –password yourP4ssword

Conclusion

There you go. Two one liners to add a vSwitch to your ESXi (or ESX) host. Both are simpler than I’d thought. Questions? Comments? Drop a line in the comments or hit me up on Twitter (@cody_bunch)

3 thoughts on “Add a vSwitch, PowerCLI vs. vCLI

  • There's no reason to ever do -VMHost (Get-VMHost X) just say -VMHost X

    My style of choice would say Get-VMHost X | New-VirtualSwitch …

    You'd probably want to throw a -Nic in there somewhere as well.

Comments are closed.