Archive for PowerCLI

How To Change Virtual Machine Network Adapter Type Using vSphere PowerCLI

The Task

You want to upgrade your VM NIC from E1000 or VMXNET to VMXNET3. There is a manual way to do this but it is quicker in Powershell

Instructions

  • Power off the VM
  • Log into Powershell – Connect-VIServer – Enter credentials if required
  • Run the following command
  • get-vm vmname | get-networkadapter | set-networkadapter -type “vmxnet3”

  • If you have more than one adapter, it will ask you about all of them. Select Y or N as required
  • Check in the VM Settings that the NIC Type has changed to VMXNET3

  • Power on VM
  • The IP Address settings that were originally set should still be there

The Manual Way (Slower)

  • Power down machine
  • Right click on machine and remove from inventory
  • Go to machine VMX file in the datastore and upload to desktop
  • Edit the vm.vmx file to ethernet0.virtualDev = “vmxnet3”
  • Rename the original vm.vmx file in the datastore to vm.vmx.bak
  • Upload the edited vm.vmx file to the datastore
  • Right click and add vm.vmx file to inventory
  • Power on machine
  • Check IP Address

Qs and As

[Q]
I have run this command while the test vm is powered off and then powered up again and the NIC has changed in the VM settings and within the Wndows 2008 R2 VM however it does not retain the IP Address. Is this standard behaviour or do we need to re-enter the IP Address?

[A]
Yes this is standard behaviour as once the NIC has been changed it is seen as a new device so a new IP will need to be assigned.

[Q]
Can this Powershell command be run while the VM is running and if so will we get the same thing where it will change the NIC type fine but not retain the IP Address?

[A]
No the command will not work while the VM is running. You can “add” a new adapter while the VM is running but to change the adapter type from E1000 to VMXNET3 the VM need to be powered off

Find memory/CPU reservation on all VMs

Find memory/CPU reservation on all VMs

To retrieve the settings for reservation of both memory and CPU run the following PS scripts

## retrieve the values for MemReservationMB for the given VMs
Get-Cluster “myCluster” | Get-VM | Get-VMResourceConfiguration | select VM,MemReservationMB

## retrieve the values for CPUReservationMhz for the given VMs
Get-Cluster “myCluster” | Get-VM | Get-VMResourceConfiguration | select VM,CPUReservationMhz

If you want to go through a set all VM memory/CPU reservations to “0” run the following

## set the MemReservationMB to 0 for given VMs
Get-Cluster “myCluster” | Get-VM | Get-VMResourceConfiguration | Set-VMResourceConfiguration -MemReservationMB 0 -Confirm:$false

## set the CPUReservationMhz to 0 for given VMs
Get-Cluster “myCluster” | Get-VM | Get-VMResourceConfiguration | Set-VMResourceConfiguration -CPUReservationMhz 0 -Confirm:$false

PowerCLI Poster 4.0 and 5.0

Poster of PowerCLI commands for VMware 4.0 +

http://communities.vmware.com/servlet/JiveServlet/download/1597600-42488/PowerCLI-Poster-4.1.pdf;jsessionid=2765C5954C484E4EA249B1702441E330

Poster of PowerCLI commands for VMware 5.0

http://communities.vmware.com/servlet/JiveServlet/download/1821950-70918/VMware%20Management%20with%20PowerCLI%205.0.pdf

The new poster adds to the original vSphere PowerCLI core cmdlets and allow you to quickly reference cmdlets from the following :

  • vSphere
  • Image Builder
  • Auto Deploy
  • Update Manager
  • Licensing
  • View
  • vCloud