Add / Remove port groups and VLANs using the ESXi command line

Useful commands for modifying port groups and VLAN settings on ESXi. Can be used in scripts of course to do additions / removals / changes in bulk.

List vSwitches:
=============================================

List port groups
=============================================

Add port group named “VLAN-900” to vSwitch0
=============================================

Assign VLAN 900 to port group “VLAN-900”
=============================================

Delete port group TEST from vSwitch0
=============================================

Restore XenServer VM snapshots from the CLI / command line

Taking a snapshot from the command line is trivial. Restoring the snapshot is not. From the XenCenter GUI application it’s easy of course, but sometimes you need to automate things. In this case I have an environment for testing which needs to be reverted to the same state after each test.

Each VM has only a single snapshot. Matching the snapshot UUID with the UUID of the virtual machine isn’t easy, but can be done by extracting the parameter called “children” from the snapshot.

To list the snapshots with their respective VM UUID’s, I use the following (i and j variables for snapshot UUID and VM UUID respectively):

To restore the snapshots:

NOTE: This works if there’s only ONE snapshot per VM and you want to restore them all. Otherwise more complex scripting is required to filter out the ones you need. It’s more than enough for our test systems though.