VMware vSphere PowerCLI User's Guide
vSphere PowerCLI 5.1 Release 1
This document supports the version of each product listed and
supports all subsequent versions until the document is replaced
by a new edition. To check for more recent editions of this
document, see http://www.vmware.com/support/pubs.
EN-000896-00
VMware vSphere PowerCLI User's Guide
2 VMware, Inc.
You can find the most up-to-date technical documentation on the VMware Web site at:
http://www.vmware.com/support/
The VMware Web site also provides the latest product updates.
If you have comments about this documentation, submit your feedback to:
docfeedback@vmware.com
Copyright
©
1998 – 2012 VMware, Inc. All rights reserved. This product is protected by U.S. and international copyright and
intellectual property laws. VMware products are covered by one or more patents listed at
http://www.vmware.com/go/patents.
VMware is a registered trademark or trademark of VMware, Inc. in the United States and/or other jurisdictions. All other marks
and names mentioned herein may be trademarks of their respective companies.
VMware, Inc.
3401 Hillview Ave.
Palo Alto, CA 94304
www.vmware.com
Contents
VMware vSphere PowerCLI User's Guide 7
1
Introduction to VMware vSphere PowerCLI 9
Microsoft PowerShell Basics 9
PowerShell Command-Line Syntax 9
PowerShell Pipelines 10
PowerShell Wildcards 10
PowerShell Common Parameters 10
vSphere PowerCLI Concepts 10
vSphere PowerCLI Components and Versioning 11
Interoperability Between the vSphere PowerCLI and vCloud Director PowerCLI Snapins 12
Selecting Objects in vSphere PowerCLI 14
Running vSphere PowerCLI Cmdlets Asynchronously 15
Managing Default Server Connections 15
Customization Specification Objects in vSphere PowerCLI 15
vSphere PowerCLI Views Cmdlets 16
Using ESXCLI with vSphere PowerCLI 16
vSphere PowerCLI Inventory Provider 16
vSphere PowerCLI Datastore Provider 16
vSphere PowerCLI About Articles 17
2
Installing VMware vSphere PowerCLI 19
Supported Operating Systems 19
Supported VMware Environments 20
Prerequisites for Installing and Running vSphere PowerCLI 20
Install vSphere PowerCLI 20
Set the Properties to Support Remote Signing 21
Uninstall vSphere PowerCLI 21
3
Configuring VMware vSphere PowerCLI 23
Scoped Settings of vSphere PowerCLI 23
Configuring the Scope of the vSphere PowerCLI Settings 23
Priority of Settings Scopes in vSphere PowerCLI 24
vSphere PowerCLI Configuration Files 24
Loading the Script Configuration File of vSphere PowerCLI 25
Load the Script Configuration File in Other PowerShell Tools 25
Customizing vSphere PowerCLI with Script Configuration Files 26
Using Custom Scripts to Extend the Operating System Support for vSphere PowerCLI Cmdlets 26
4
Using VMware vSphere PowerCLI Views from .NET 27
vSphere PowerCLI Views 27
VMware, Inc.
3
Set Up the Environment to Develop vSphere PowerCLI .NET Applications 28
Updating the Properties of vSphere PowerCLI Views 28
Creating and Using Filters with VimClient.FindEntityView() or VimClient.FindEntityViews() 29
Saving and Using Server Sessions with vSphere PowerCLI Views 30
Handling Server Errors with vSphere PowerCLI Views 30
5
Sample Scripts for Managing vSphere with VMware vSphere PowerCLI 31
Connect to a vCenter Server system 34
Manage Virtual Machines on vSphere 34
Add a Standalone Host to a vCenter Server System 35
Activate Maintenance Mode for a Host on vCenter Server 35
Create vSphere Inventory Objects 36
Create Virtual Machines on vCenter Server Using an XML Specification File 37
Manage Virtual Machine Templates on vCenter Server 37
Create and Use Snapshots on vCenter Server 38
Update the Resource Configuration Settings of a Virtual Machine on vCenter Server 38
Get a List of Hosts on a vCenter Server System and View Their Properties 39
Change the Host Advanced Configuration Settings on vCenter Server 39
Move a Virtual Machine to a Different Host Using VMware vSphere vMotion 40
Move a Virtual Machine to a Different Datastore Using VMware vSphere Storage vMotion 40
Create a Host Profile on a vCenter Server System 40
Apply a Host Profile to a Host on vCenter Server 41
Manage Statistics and Statistics Intervals on vCenter Server 41
Modify the Settings of the NIC Teaming Policy for a Virtual Switch 42
Create a vApp on vCenter Server 42
Modify the Properties of a vApp 43
Export or Import vApps 43
Configure a Network Interface 43
Add a Guest Route 44
Create an iSCSI Host Storage 44
Add Passthrough Devices to a Host and Virtual Machine 45
Create a Custom Property Based on an Extension Data Property 45
Create a Script-Based Custom Property for a vSphere Object 45
Apply a Customization Object to a Cloned Virtual Machine 46
Modify the Default NIC Mapping Object of a Customization Specification 46
Modify Multiple NIC Mapping Objects of a Customization Specification 47
Create a vSphere Role and Assign Permissions to a User 47
View the Action Triggers for an Alarm on vCenter Server 48
Create and Modify Alarm Actions and Alarm Triggers on vCenter Server 48
Remove Alarm Actions and Triggers 49
Create and Modify Advanced Settings for a Cluster 49
Modify the vCenter Server Email Configuration 50
Modify the vCenter Server SNMP Configuration 50
Use Esxtop to Get Information on the Virtual CPUs of a Virtual Machine 50
Filter vSphere Objects with Get-View 51
Populate a View Object with Get-View 52
Update the State of a Server-Side Object 52
Reboot a Host with Get-View 53
Modify the CPU Levels of a Virtual Machine with Get–View and Get–VIObjectByVIView 53
VMware vSphere PowerCLI User's Guide
4 VMware, Inc.
Browse the Default Inventory Drive 53
Create a New Custom Inventory Drive 54
Manage Inventory Objects Through Inventory Drives 54
Browse the Default Datastore Drives 55
Create a New Custom Datastore Drive 55
Manage Datastores Through Datastore Drives 56
Modify the Timeout Setting for Web Tasks 56
6
Sample Scripts for Managing vCloud Director with
VMware vCloud Director PowerCLI 59
Connect to a vCloud Director Server 60
Create and Manage Organizations 61
Create and Manage Organization Virtual Datacenters 61
Create and Manage Organization Networks 62
Filter and Retrieve Organization Networks 63
Import a vApp Template from the Local Storage 63
Create a vApp Template from a vApp 63
Import a vApp from vSphere 64
Create and Modify a vApp 64
Manage Virtual Machines with vApps 65
Manage Virtual Machines and Their Guest Operating Systems 65
Retrieve a List of the Internal and External IP Addresses of Virtual Machines in vApps 66
Create and Manage Access Control Rules 67
Filter and Retrieve vApp Networks 67
Create vApp Networks for a Selected vApp 68
Create an Isolated vApp Network 68
Create an NAT-Routed vApp Network 68
Create a Direct vApp Network 69
Modify or Remove vApp Networks 69
Index 71
Contents
VMware, Inc. 5