Archive for March 2013

Use Web Service Access Cmdlets

index

What are the Web Service Access Cmdlets?

The vSphere PowerCLI 4.1 list of cmdlets includes two Web Service Access cmdlets:

  • Get-View
  • Get-VIObjectByVIView

They enable access to the programming model of the vSphere SDK for .NET from PowerShell and can be used to initiate vSphere .NET objects. Each object:

  • Is a static copy of a server-side managed object and is not automatically updated when the object on the server changes.
  • Includes properties and methods that correspond to the properties and operations of the server-side managed object. For more informat ion about server-side object methods and properties, check the VMware vSphere API Reference Guide

Using the Web Service Access cmdlets for low-level VMware vSphere management requires some knowledge of both PowerShell scripting and the VMware vSphere API

The reason people seem to be using the Get-View cmdlet is the fact it is known to be faster than using other PowerCLI cmdlets for getting info (such as Get-VM, Get-VMHost, Get-Datastore, etc.) Some things can’t be done using powercli cmdlets, and they need to be executed using views and their methods. Views also  provide access to specific managers like license manager, alarm manager etc…

Example 1

These 2 commands do the same thing

  • $vm = Get-View -ViewType VirtualMachine -Filter @{“Name” = “hostname”}
  • $vm = Get-VM hostname | Get-View

web

Example 2: Filter vSphere Objects

This procedure illustrates the use of the Get-View cmdlet in combination with a filter. The filter parameter is a HashTable containing one or more pairs of filter criteria. Each of the criteria consists of a property path and a value that represents a regular expression pattern used to match the property.

The filter in this procedure gets a list of the powered on virtual machines whose guest OS names contain “Windows XP”. The Get-View cmdlet then initiates shutdown for each guest operating system in the list.

shell2

Example 3: To modify the CPU levels of a virtual machine

This example shows how to modify the CPU levels of a virtual machine using combination of the Get-View and Get-VIObjectByVIView cmdlets

shell3

Viewtype from get-view supports those views:

  • ComputeResource
  • ClusterComputeResource
  • Datacenter, Datastore
  • Network
  • DistributedVirtualPortgroup
  • DistributedVirtualSwitch
  • Folder
  • HostSystem
  • ResourcePool
  • VirtualApp
  • VirtualMachine
  • VmwareDistributedVirtualSwitch

Guide

vSphere PowerCLI Administration Guide

Useful Websites

http://franckrichard.blogspot.co.uk/2011/06/optimize-your-vmware-powershell-part-1.html

http://vnugglets.com/2012/08/even-faster-powercli-code-with-get-view.html

Use basic and advanced Cmdlets to manage VMs and ESX Hosts

index

Some useful commands for working with PowerCLI on VMware objects

The best thing to do is to get lots of practice in with these commands

powershell

The most useful PowerShell book

This book is great for beginners and a complete introduction to PowerShell. The concepts can then be applied to PowerCLI

POWERSHELLBOOK

Useful PowerShell GUIs

Note: These will be useful for practicing Powershell with the concepts you learn being able to be applied to PowerCLI

PowerGUI

This is a free tool that is extremely useful to use PowerCLI productively and comes with a ton of pre-created scripts. That tool is PowerGUI and it includes the VMware Community PowerPack.

SAPIEN PrimalScript and PrimalForms

Two commercial tools

PowerSE and PowerWF

A free editor and a commercial workflow solution from

Idera PowerShell Plus

An editor and console environment

VMware Onyx

This tool acts as a proxy server between your vSphere Client and vCenter server. The Onyx console shows you everything you do in the vSphere Client generated as a PowerCLI script (automatically) that you can use and modify however you like