This section provides sample scripts that illustrate managing vSphere with PowerCLI cmdlets.

To run PowerCLI cmdlets on vSphere and perform administration or monitoring tasks, first establish a connection to an ESX instance or a vCenter Server.

With VMware vSphere PowerCLI, you can automate various administration tasks on virtual machines, for example retrieving information, shutting down and powering off virtual machines.

You can add standalone hosts to a vSphere server by using the Add-VMHost cmdlet. After adding the hosts, you will be able to manage them through the vSphere server.

To complete some specific administration tasks, you might need to activate maintenance mode for a host. On vSphere, you can activate maintenance mode by using the Set-VMHost cmdlet.

By using PowerCLI cmdlets, you can automate creating different inventory objects on vSphere.

You can use a specification provided in an XML file to automate the creation of virtual machines on vSphere.

You can use PowerCLI to create virtual machines templates and convert them to virtual machines on vSphere.

You can use the Snapshot parameter of Get-VM to take a snapshot of virtual machines and then revert the virtual machines' states back to the snapshot.

You can use the Set-VMResourceConfiguration cmdlet to modify the resource configuration properties of a virtual machine, including memory, CPU shares, and other settings.

With PowerCLI, you can get information about all available hosts in a datacenter and view their properties.

You can modify host configuration, including advanced settings related to virtual machine migration, and apply them to another host.

You can migrate a virtual machine between vSphere hosts by using VMware vMotion.

You can migrate a virtual machine between datastores using the VMware Storage vMotion feature of vSphere.

The VMware Host Profiles feature enables you to create standard configurations for ESX and ESXi hosts. With PowerCLI, you can automate creation and modifying of host profiles.

To simplify operational management of large-scale environments, you can apply standard configurations called host profiles to hosts on vSphere. If you want to set up a host to use the same host profile as a refernce host, you can attach the host to a profile.

You can use the PowerCLI cmdlets to automate tasks for viewing and managing statistics for vSphere inventory objects.

You can specify the NIC teaming policy on a vSwitch. The NIC teaming policy determines the load balancing and failover settings of a virtual switch and allows you to specify unused NICs.

With PowerCLI, you can create and manage virtual appliances.

With PowerCLI, you can start and stop virtual appliances, and modify their properties.

You can import and export virtual appliances to OVA and OVF files.

You can modify the IP and routing configuration settings of a guest network interface.

You can add new guest routes for virtual machines and modify the routes properties.

For a host, you can enable iSCSI, add iSCSI targets, and create new host storages.

You can get information about existing passthrough devices and add new SCSI and PCI devices to virtual machines and hosts.

You can create custom properties to add more information to vSphere objects. Custom properties based on extension data properties correspond directly to the property of the corresponding .NET view object.

You can create a custom property by writing a script and providing a name for the property. The script evaluates when the custom property is called for first time.

You can apply a custom configuration to a cloned virtual machine by using a customization object.

You can modify the default NIC mapping object of a customization specification and apply the specification on a newly created virtual machine.

You can modify multiple NIC mapping objects of a customization specification and apply the specification to an existing virtual machine.

With PowerCLI, you can automate management of vSphere permissions, roles, and privileges.

You can see which action triggers are configured for an alarm.

With PowerCLI, you can create and modify vSphere alarm actions and alarm triggers.

In some cases, you might want to remove obsolete alarm actions and triggers.

You can customize the behavior of a cluster on vSphere by creating and modifying custom advanced settings for it.

You can modify the email configuration settings of a vCenter Server.

To use SNMP, you must first configure the SNMP settings of the vCenter Server.

You can use the Get-ESXTop cmdlet to retrieve real-time data for troubleshooting performance problems.

You can use the Get-View cmdlet to filter vSphere objects before performing various actions on them.

You can use the Get-View cmdlet to update a view object by using the information from a previously called managed object.

You can use the Get-View cmdlet to update server-side objects.

You can reboot a host by using its corresponding view object.

You can modify the CPU levels of a virtual machine using a combination of the Get-View and Get-VIObjectByVIView cmdlets.

You can browse the default inventory drive and view its contents.

In addition to the default drive, you can create new custom inventory drives by using the New-PSDrive cmdlet.

You can use the PowerCLI Inventory Provider to browse, modify, and remove inventory objects from inventory drives.

You can use the PowerCLI Datastore Provider to browse the default datastore drives: vmstore and vmstores.

You can use the PowerCLI datastore provider to create custom datastore drives.

You can use the PowerCLI Datastore Provider to browse datastores from datastore drives.