PowerCLI Related VCAP-DCA Objectives

by admin

There are a number of objectives relating to PowerCLI on the VCAP-DCA blueprint, some of which I have covered, here and here. I have also given PowerCLI examples as an alternative to CLI command or vSphere Client actions for certain tasks such as backing up a ESXi hosts configuration. The specific objectives that I haven’t covered elsewhere are:

  • Use basic and advanced Cmdlets to manage VMs and ESXi Hosts
  • Use Web Service Access Cmdlets
  • Use Datastore and Inventory Providers
  • Given a sample script, modify the script to perform a given action

Use basic and advanced Cmdlets to manage VMs and ESXi Hosts

There are many 100s of cmdlets that can be used to manage a vSphere environment. A number of the articles on this site detail PowerCLI methods for completing a given task. A good starting point though may be VMware’s PowerCLI User Guide, which has many good examples. You can also use the get-help and get-command cmdlets to help you find the correct cmdlet for the task you are carrying out.

The get-command cmdlet will display all the available cmdlets:

get-command

The get-help cmdlet can then be used to get information about a specific cmdlet. For example:

get-help get-vm

get-help-get-vm

Use Web Service Access Cmdlets

Get-view and get-viobjectbyviview are web services access cmdlets. They enable access to the programming model of the vSphere SDK for .NET from PowerShell and can be used to initiate vSphere .NET objects. An example of using get-view can be seen below:

get-view-example

You can read more about web service access cmdlets on page 26 of the PowerCLI user guide.

Use Datastore and Inventory Providers

The datastore provider allows you to access the contents of a VMFS datastore using PowerCLI. There are two default datastore drives: vmstore: and vmstores:. The vmstores: drive contains all the datastores that are accessible to the host or vCenter to which the PowerCLI session is established:

vmstores

You can navigate the vmstore in the same way as you would browse the local file system. You can also upload and download files to and from the datastores and copy files between datastores using cmdlets such as copy-item and copy-datastoreitem. More on this on page 29 of the PowerCLI guide.

Given a sample script, modify the script to perform a given action

This is a difficult objective to cover given that you can put together some PowerCLI/Shell code to do most tasks. Looking at the examples for the various cmdlets is a good place to start to get an idea what each do, and what to modify to change their behavior. For example, try running:

get-help get-vm -examples

This works with most cmdlets and will show you examples of how the cmdlets can be used:
get-help-examples


Keep up to date with new posts on Buildvirtual.net - Follow us on Twitter:
Be Sociable, Share!

Leave a Comment

*

Previous post:

Next post: