Archive for PowerCLI

Install and Configure vSphere PowerCLI

index

What is vSphere PowerCLI?

vSphere PowerCLI provides easy-to-use C# and PowerShell interface to VMware vSphere APIs. It ships with a number of cmdlets that you can use to perform various administration tasks on VMware vSphere components

Installation Pre-Requisites

  • .NET 2.0 SP1
  • Windows PowerShell 1.0/2.0/3.0

Supported Operating Systems
VMware vSphere PowerCLI 5.0 is supported on the 32-bit and 64-bit versions of the following Windows operating systems:

  • Windows 7
  • Windows Server 2008
  • Windows Vista
  • Windows XP Service Pack 2
  • Windows 2003 Server Service Pack 2

Supported VMware Environments

vSphere PowerCLI 5.0 is compatible with the following VMware environments:

  • VMware ESXi 5.0
  • vCenter Server 5.0
  • VMware ESX 4.1/vCenter Server 4.1
  • VMware ESXi 4.1
  • VMware ESX 4.0 Update 2/vCenter Server 4.0 Update 2
  • VMware ESX 4.0 Update 1/vCenter Server 4.0 Update 1
  • VMware ESX 4.0i Update 1
  • VMware ESX 3.5 Update 5
  • VMware ESXi 3.5 Update 5
  • VMware VirtualCenter 2.5 Update 6
  • VMware ESX 3.0.3 Update 1

Identify Cmdlet Concepts

PowerShell cmdlets use a consistent verb-noun structure, where the verb specifies the action and the noun specifies the object to operate on. PowerShell cmdlets follow consistent naming patterns, which makes it easy to figure out how to construct a command if you know the object you want to work with.
All command categories take parameters and arguments. A parameter starts with a hyphen and is used to control the behavior of the command. An argument is a data value consumed by the command.

PowerShell

 PowerCLI Components

To use these snap-ins, you must add them using the add-pssnapin cmdlet.

Example

  • add-pssnapin vmware.vimautomation.core

power

Installing

  • Download PowerCLI from the VMware website
  • Click the exe and install
  • You may get a message such as below

Power2

  • And this message – Click Continue

power3

  • Click Next

power4

  • Click Next

power5

  • Click Next

power7

  • Keep the default selection

power8

  • Click Install

power9

Configuring PowerCLI

Set the properties for Remote Signing

For security reasons, Windows PowerShell supports an execution policy feature. It determines whether scripts are allowed to run and whether they must be digitally signed. By default, the execution policy is set to Restricted, which is the most secure policy. If you want to run scripts or load configuration files, you can change the execution policy by using the Set-ExecutionPolicy cmdlet. For more information about the execution policy and script digital signing in Windows PowerShell, run Get-Help About_Signing.

  • Right click on the PowerCLI icon and selecy Run as Administrator
  • Type Set-ExecutionPolicy RemoteSigned

power10

Slow Startup

I experienced a really slow start-up from PowerCLI. It had something to do with internet access and checking the certificates. I disabled this by doing the below

  • Open the Control Panel → Go To Internet Options → Go to the Advanced tab → Go to the Security Section
  • Un-check the “Check for publisher’s certificate revocation” check-box

TIP

Certificate Errors

Certificate error can generally be ignored but if you want to make sure they don’t come up try typing the following

  • Set-PowerCLIConfiguration -invalidCertificateAction ignore -confirm:$false

power11

Guides

vSphere PowerCLI User Guide

PowerCLI cmdlet Reference

PowerShell Community

http://communities.vmware.com/community/vmtn/server/vsphere/automationtools/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