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
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.
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
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