Vmware Powercli 127 User Guide
Vmware Powercli 127 User Guide
Guide
VMware PowerCLI™
VMware PowerCLI User's Guide
You can find the most up-to-date technical documentation on the VMware website at:
https://docs.vmware.com/
VMware, Inc.
3401 Hillview Ave.
Palo Alto, CA 94304
www.vmware.com
©
Copyright 1998-2022 VMware, Inc. All rights reserved. Copyright and trademark information.
VMware, Inc. 2
Contents
Updated Information 10
VMware, Inc. 3
VMware PowerCLI User's Guide
VMware, Inc. 4
VMware PowerCLI User's Guide
VMware, Inc. 5
VMware PowerCLI User's Guide
VMware, Inc. 6
VMware PowerCLI User's Guide
VMware, Inc. 7
VMware PowerCLI User's Guide
VMware, Inc. 8
VMware PowerCLI User's Guide
The VMware PowerCLI User's Guide provides information about installing and using the VMware
PowerCLI cmdlets (pronounced “commandlets”) for managing, monitoring, automating, and
®
handling operations for VMware vSphere, VMware Site Recovery Manager, vSphere Automation
API, vSAN, VMware Cloud Director, vSphere Update Manager, vRealize Operations Manager,
VMware Horizon, VMware NSX, VMware HCX, and VMware Cloud on AWS components.
To help you start with PowerCLI, this documentation includes descriptions of specific PowerCLI
concepts and features. In addition, this documentation provides a set of use case examples and
sample scripts.
Intended Audience
This guide is intended for anyone who wants to install and use PowerCLI. This documentation is
written for administrators and developers who are familiar with virtual machine technology and
PowerShell.
n Basic administrators can use cmdlets included in PowerCLI to manage their vSphere, VMware
Site Recovery Manager, vSphere Automation API, vSAN, VMware Cloud Director, vSphere
Update Manager, vRealize Operations Manager, VMware Horizon, VMware NSX, VMware
HCX, and VMware Cloud on AWS infrastructure from the command line.
n Advanced administrators can develop PowerShell scripts that other administrators can reuse
or integrate into other applications.
VMware, Inc. 9
Updated Information
This section is updated with each release of the product or when necessary.
This table tracks record of the updated information in the VMware PowerCLI User's Guide starting
from the 12.4.0 release.
PowerCLI Version /
Publish Date Description
12.7.0 / 08 AUG n Added information on how to connect to a vCenter Server that is federated to Active Directory
2022 Federation Services (AD FS). See Connect to an AD FS - Federated vCenter Server System.
12.6.0 / 07 APR n Removed non-inclusive language terms from the PowerCLI User's Guide and replaced them
2022 with appropriate alternatives.
n Added a new module, VMware.Sdk.Nsx.Policy, to PowerCLI Modules.
12.5.0 / 13 JAN 2022 n Added information on how to manage the certificates of your vSphere environment with
VMware PowerCLI. See the new chapter Managing Certificates.
12.4.0 / 16 SEP 2021 n Added information about the new VMware PowerCLI modules for the 12.4.0 release. See
PowerCLI Modules.
n Updated the chapter on managing VMware Cloud on AWS with PowerCLI and added many new
scripts. See Chapter 12 Managing VMware Cloud on AWS with VMware PowerCLI .
n Added information, procedures, and sample scripts for the vSphere Automation SDK for
PowerShell, which was introduced in VMware PowerCLI 12.4.0. See Chapter 8 Managing the
vSphere Automation API with VMware PowerCLI.
VMware, Inc. 10
Introduction to VMware PowerCLI
1
VMware PowerCLI contains modules of cmdlets based on Microsoft PowerShell for automating
vSphere, VMware Site Recovery Manager, vSphere Automation API, vSAN, VMware Cloud
Director, vSphere Update Manager, vRealize Operations Manager, VMware Horizon, VMware
NSX, VMware HCX, and VMware Cloud on AWS administration. VMware PowerCLI provides a
PowerShell interface to the VMware product APIs.
n PowerCLI Concepts
PowerCLI cmdlets are created to automate VMware environments administration and to
introduce some specific features in addition to the PowerShell concepts.
Microsoft PowerShell is both a command-line and scripting environment. It uses the .NET object
model and provides administrators with system administration and automation capabilities. To
work with PowerShell, you run commands, named cmdlets.
n PowerShell Pipelines
A pipeline is a series of commands separated by the pipe operator |.
n PowerShell Wildcards
PowerShell has a number of pattern-matching operators named wildcards that you can use to
substitute one or more characters in a string, or substitute the complete string.
VMware, Inc. 11
VMware PowerCLI User's Guide
PowerShell cmdlets follow consistent naming patterns, ensuring that construction of a command is
easy if you know the object that you want to work with.
All command categories take parameters and arguments. A parameter starts with a hyphen and
is used to control the behavior of the command. An argument is a data value consumed by the
command.
PowerShell Pipelines
A pipeline is a series of commands separated by the pipe operator |.
Each command in the pipeline receives an object from the previous command, performs some
operation on it, and then passes it to the next command in the pipeline. Objects are output from
the pipeline as soon as they become available.
PowerShell Wildcards
PowerShell has a number of pattern-matching operators named wildcards that you can use to
substitute one or more characters in a string, or substitute the complete string.
All wildcard expressions can be used with the PowerCLI cmdlets. For example, you can view a
list of all files with a .txt extension by running dir *.txt. In this case, the asterisk * operator
matches any combination of characters.
With wildcard patterns you can indicate character ranges as well. For example, to view all files that
start with the letter S or T and have a .txt extension, you can run dir [st]*.txt.
You can use the question mark ? wildcard to match any single character within a sequence of
characters. For example, to view all .txt files with names that consist of string and one more
character at the end, run dir string?.txt.
VMware, Inc. 12
VMware PowerCLI User's Guide
PowerCLI Concepts
PowerCLI cmdlets are created to automate VMware environments administration and to introduce
some specific features in addition to the PowerShell concepts.
n PowerCLI Modules
VMware PowerCLI consists of multiple modules that you can install and use according to your
needs and environments.
n Interoperability Between the PowerCLI and VMware Cloud Director PowerCLI Modules
With the RelatedObject parameter of PowerCLI cmdlets, you can retrieve vSphere
inventory objects from cloud resources. This interoperability between the PowerCLI and
VMware Cloud Director PowerCLI modules expands cloud administration, automation,
reporting, and troubleshooting options for provider administrators.
VMware, Inc. 13
VMware PowerCLI User's Guide
PowerCLI Modules
VMware PowerCLI consists of multiple modules that you can install and use according to your
needs and environments.
Module Description
VMware, Inc. 14
VMware PowerCLI User's Guide
Module Description
VMware, Inc. 15
VMware PowerCLI User's Guide
Cloud Director PowerCLI modules expands cloud administration, automation, reporting, and
troubleshooting options for provider administrators.
Note To use the interoperability feature, you must install the PowerCLI and VMware Cloud
Director PowerCLI modules, and connect both to a VMware Cloud Director server and a vCenter
Server system.
Table 1-1. List of Supported vSphere Inventory Objects You Can Retrieve from Cloud Objects
Sample Script for Retrieving the
Cloud Object Retrieved vSphere Inventory Object vSphere Inventory Object
ProviderVdc Datastore
Get-ProviderVdc -Name
'MyProviderVdc' | Get-
Datastore
CIVM VirtualMachine
Get-CIVM -Name 'MyCloudVM'
| Get-VM
NetworkPool VDSwitch
Get-NetworkPool -Name
'MyNetworkPool' | Get-
VDSwitch
NetworkPool VDPortgroup
Get-NetworkPool -Name
'MyNetworkPool' | Get-
VDPortGroup
ExternalNetwork VDPortgroup
Get-ExternalNetwork -Name
'MyExternalNetwork' | Get-
VDPortGroup
VMware, Inc. 16
VMware PowerCLI User's Guide
Instead of assigning an object name to a cmdlet parameter, users can pass the object through a
pipeline or a variable. For example, the following three commands are interchangeable:
If you provide a non-existing object name, an OBN failure occurs. In such cases, PowerCLI
generates a non-terminating error and runs the cmdlet ignoring the invalid name.
If the VM2 virtual machine does not exist on either of the selected servers, PowerCLI generates a
non-terminating error and applies the command only on the VM1 and VM3 virtual machines.
To escape non-alphanumeric characters in PowerCLI, you need to place the expression that
contains them in single quotes (').
Note When you provide your login credentials in the Specify Credential dialog box, you do not
need to escape non-alphanumeric characters.
VMware, Inc. 17
VMware PowerCLI User's Guide
When you use the RunAsync parameter, the cmdlet returns Task objects instead of its usual
output. The Status property of a returned Task object contains a snapshot of the initial state of
the task. This state is not updated automatically and has the values Error, Queued, Running, or
Success. You can refresh a task state by retrieving the task object with the Get-Task cmdlet. If
you want to observe the progress of a running task and wait for its completion before running
other commands, use the Wait-Task cmdlet.
Note In PowerCLI, the RunAsync parameter affects only the invocation of a cmdlet and does not
control whether the initiated tasks run consecutively or in parallel. For example, the Remove-VM
cmdlet might remove the selected virtual machines simultaneously or consecutively depending on
the internal design of PowerCLI. To make sure that tasks initiated by a cmdlet run consecutively,
run the cmdlet in a loop, each time applying it to a single object.
The command returns no output when all virtual machines stored in the $vmList variable are
removed, irrespective of whether they are removed simultaneously.
The command returns an output that consists of one or more Task objects immediately.
When you connect to a vCenter Server system by using Connect-VIServer, the server
connection is stored in the $DefaultVIServers array variable. This variable contains all connected
servers for the current PowerCLI session. To remove a server from the $DefaultVIServers variable,
you can either use Disconnect-VIServer to close all active connections to this server, or modify
the value of $DefaultVIServers manually.
When you connect to a VMware Cloud Director system by using Connect-CIServer, the server
connection is stored in the $DefaultCIServers array variable. This variable contains all connected
servers for the current session. To remove a server from the $DefaultCIServers variable, you can
either use Disconnect-CIServer to close all active connections to this server, or modify the
value of $DefaultCIServers manually.
VMware, Inc. 18
VMware PowerCLI User's Guide
Persistent Customization
Persistent customization specification objects are stored on the vSphere server. All persistent
customization specifications created by using vSphere Client or VMware PowerCLI 4.1 or later
are encrypted. Encrypted customization specifications can be applied only by the server that has
encrypted them.
Nonpersistent Customization
Nonpersistent customization specification objects exist only inside the current PowerShell process.
Nonpersistent customization specification objects are not encrypted, but cloning them to a
vSphere server encrypts them.
n Through the Get-ESXCli cmdlet, which provides direct access to the ESXCLI namespaces,
applications, and commands.
n Through .NET methods, which you use to create managed objects that correspond to specific
ESXCLI applications. To access the ESXCLI, you can call methods on these managed objects.
Note To call a method of an ESXCLI object, you must provide values for all parameters. If you
want to omit a given parameter, pass $null as its argument.
It enables navigation and file-style management of the VMware vSphere inventory. By creating a
PowerShell drive based on a managed object (such as a data center), you can obtain a view of its
contents and the relationships between the items. In addition, you can move, rename, or delete
objects by running commands from the PowerShell console.
When you connect to a server with Connect-VIServer, the cmdlet builds two default inventory
drives: vi and vis. The vi inventory drive shows the inventory on the last connected server. The
vis drive contains the inventory of all vSphere servers connected within the current PowerCLI
session.
You can use the default inventory drives or create custom drives based on the default ones.
VMware, Inc. 19
VMware PowerCLI User's Guide
The items in a datastore are files that contain configuration, virtual disk, and the other data
associated with a virtual machine.
When you connect to a server with Connect-VIServer, the cmdlet builds two default datastore
drives: vmstore and vmstores. The vmstore drive provides a list of the datastores available on
the vSphere server that you last connected to.
Note If you establish multiple connections to the same vSphere server, the vmstore drive is not
updated.
The vmstores drive contains all datastores available on all vSphere servers that you connected to
within the current PowerCLI session.
You can use the default datastore drives or create custom drives based on the default ones.
Running Help About_* lists all built-in PowerShell and VMware PowerCLI about articles.
Object-by-Name (OBN) Help About_OBN To help you save time and effort,
PowerCLI lets you select objects by
their names.
VMware PowerCLI Objects Help About_PowerCLI_Objects For their input and output, the
PowerCLI cmdlets use a set
of .NET types that reside in the
VMware.VimAutomation.ViCore.Types
namespace.
Using the RunAsync Parameter Help About_RunAsync When you set the RunAsync
parameter, you indicate that you want
to run the cmdlet asynchronously.
VMware, Inc. 20
VMware PowerCLI User's Guide
Authenticating with a vCenter Server Help About_Server_Authentication To authenticate with vCenter Server
System or a VMware Cloud Director and VMware Cloud Director servers,
Server you can provide a user name
and password through the User
and Password parameters, or a
PSCredential object through the
Credential parameter.
Unique Identifiers for PowerCLI Help About_UID You can uniquely identify a PowerCLI
Objects (UID) object on a server or across multiple
servers by providing its UID.
VMware, Inc. 21
Installing VMware PowerCLI
2
VMware PowerCLI lets you manage, monitor, automate, and handle lifecycle operations on
VMware vSphere, vRealize Operations Manager, vSAN, VMware Cloud Director, vSphere Update
Manager, VMware NSX, VMware Cloud on AWS, VMware HCX, VMware Horizon, and VMware
Site Recovery Manager systems. You can install VMware PowerCLI modules on all supported
operating systems.
After installing the package on your machine, you can connect to your ESXi, vCenter Server,
vRealize Operations Manager, VMware Cloud Director, VMware NSX, VMware Cloud on AWS,
VMware Horizon, or VMware Site Recovery Manager system by providing valid authentication
credentials.
n Install PowerCLI
You can download and install PowerCLI modules from the PowerShell Gallery. You can
install all VMware PowerCLI modules with a single PowerShell command, or install modules
individually.
n Update PowerCLI
You can update PowerCLI when a new version of the product becomes available. See the
PowerShell Gallery for the latest PowerCLI versions.
VMware, Inc. 22
VMware PowerCLI User's Guide
n Uninstall PowerCLI
You can uninstall VMware PowerCLI by deleting the VMware PowerCLI modules from your
system.
For a list of VMware products with which VMware PowerCLI is compatible, see VMware Product
Interoperability Matrixes.
For a list of PowerShell versions with which VMware PowerCLI is compatible, see the Compatibility
Matrix on the PowerCLI home page.
Install PowerCLI
You can download and install PowerCLI modules from the PowerShell Gallery. You can install all
VMware PowerCLI modules with a single PowerShell command, or install modules individually.
Use the Install-Module cmdlet to download and install PowerCLI modules. See the PowerShell
Gallery for the complete list of available PowerCLI modules.
Prerequisites
n Verify that your system is compatible with PowerCLI. See the Compatibility Matrix on the
PowerCLI home page.
VMware, Inc. 23
VMware PowerCLI User's Guide
n Verify that PowerShell is available on your system. For Linux and macOS, you must install
PowerShell. See how to install PowerShell on different platforms.
Procedure
Alternatively, you can install individual PowerCLI modules by running the Install-Module
cmdlet with the module name.
3 If you see a warning that you are installing modules from an untrusted repository, press y and
then press Enter to confirm the installation.
What to do next
You might need to install PowerCLI on a local machine with no Internet connectivity due to
security reasons and deployment restrictions. If you are using such an environment, you can
download the PowerCLI ZIP file on a computer with Internet access, transfer the ZIP file to your
local machine and install PowerCLI.
Prerequisites
n Verify that your system is compatible with PowerCLI. See the Compatibility Matrix on the
PowerCLI home page.
n Verify that PowerShell is available on your system. For Linux and macOS, you must install
PowerShell. See how to install PowerShell on different platforms.
n Download the PowerCLI ZIP file from the PowerCLI home page and transfer the ZIP file to
your local machine.
Procedure
2 To view the folder paths to which you can extract the PowerCLI ZIP file, run the command:
$env:PSModulePath
VMware, Inc. 24
VMware PowerCLI User's Guide
3 Extract the contents of the PowerCLI ZIP file to one of the listed folders.
Replace folder_path with the path to the folder where you extracted the contents of the ZIP
file.
5 (Optional) Verify that the VMware PowerCLI modules have installed successfully.
Results
What to do next
For security reasons, PowerShell supports an execution policy feature. It determines whether
scripts are allowed to run and whether they must be digitally signed. By default, the execution
policy is set to Restricted, which is the most secure policy. For more information about the
execution policy and script digital signing in PowerShell, run Get-Help About_Signing.
You can change the execution policy by using the Set-ExecutionPolicy cmdlet.
Procedure
Update PowerCLI
You can update PowerCLI when a new version of the product becomes available. See the
PowerShell Gallery for the latest PowerCLI versions.
Use the Update-Module cmdlet to update PowerCLI modules. You can update all VMware
PowerCLI modules with a single command, or update modules individually.
You cannot use the Update-Module cmdlet in offline mode. To update PowerCLI in offline mode,
you must perform a new installation. See Install PowerCLI Offline.
VMware, Inc. 25
VMware PowerCLI User's Guide
Procedure
1 Open PowerShell.
Alternatively, you can update individual PowerCLI modules by running the Update-Module
cmdlet with the module name.
Uninstall PowerCLI
You can uninstall VMware PowerCLI by deleting the VMware PowerCLI modules from your
system.
To uninstall VMware PowerCLI, you must locate your VMware PowerCLI modules and delete
them.
Prerequisites
Procedure
2 In your operating system, navigate to the destination folder(s) and delete all modules that start
with VMware.
Results
VMware, Inc. 26
Configuring VMware PowerCLI
3
Configure how VMware PowerCLI responds to invalid server certificates, choose the application
settings for different users and user groups, modify the script configuration file, and add custom
scripts.
You might not be able to connect to a server because of the default action configured for
PowerCLI and untrusted certificates.
By default, PowerCLI is set to deny connections to servers with invalid certificates. You can
retrieve the current setting for invalid server certificates, and configure it as required. For more
information, see Configure the PowerCLI Response to Untrusted Certificates.
Procedure
VMware, Inc. 27
VMware PowerCLI User's Guide
n Warn. PowerCLI logs a warning message that a certificate is not valid, displays additional
information about the certificate, and establishes the connection.
n Prompt. If a server certificate is not valid, PowerCLI prompts you to choose an action
before it continues. You can choose one of the following options.
Option Action
Accept Once Establish the server connection and suppress further warnings for the current PowerShell
session.
Accept Permanently Save the server certificate in the PowerCLI Trusted Certificate Store for the current user
and establish the server connection.
Accept For All Users Save the server certificate both in the current user's Trusted Certificate Store and in the all
users' Trusted Certificate Store and establish the server connection.
Note For Linux and macOS, only the Fail and Ignore options are supported.
A warning message prompts you to confirm the operation. Press Y and then press Enter to
confirm your choice.
Results
You configured the invalid server certificate action setting. PowerCLI displays a table with the
updated configuration settings.
What to do next
Note You must permanently accept at least one certificate as trusted for the CSV file to appear on
your system.
The certificate store file is saved in a different location depending on the type of user. For
more information about the exact file path of the trusted certificate store file, see PowerCLI
Configuration Files.
VMware, Inc. 28
VMware PowerCLI User's Guide
For greater control over the PowerCLI configuration, the Set-PowerCLIConfiguration cmdlet
provides the Scope parameter.
VMware, Inc. 29
VMware PowerCLI User's Guide
Note You must have administrator privileges to change the settings for AllUsers.
VMware, Inc. 30
VMware PowerCLI User's Guide
Users with advanced knowledge and understanding of PowerShell and VMware PowerCLI
can manually modify the contents of PowerCLI_settings.xml to change PowerCLI settings.
Modifying PowerCLI_settings.xml might require administrator privileges.
VMware, Inc. 31
Configuring Customer Experience
Improvement Program 4
When you choose to participate in the Customer Experience Improvement Program (CEIP),
VMware receives anonymous information to improve the quality, reliability, and functionality of
VMware products and services.
Details regarding the data collected through CEIP and the purposes for which it is used by
VMware are set forth at the Trust & Assurance Center at http://www.vmware.com/trustvmware/
ceip.html. To join or leave the CEIP for this product, see Join the Customer Experience
Improvement Program in PowerCLI.
Procedure
u Run Set-PowerCLIConfiguration.
VMware, Inc. 32
Managing vSphere with VMware
PowerCLI 5
To help you get started with VMware PowerCLI, this documentation provides a set of sample
scripts that illustrate basic and advanced tasks in vSphere administration.
VMware, Inc. 33
VMware PowerCLI User's Guide
n Get a List of Hosts on a vCenter Server System and View Their Properties
With PowerCLI, you can get information about all available hosts in a data center and view
their properties.
n Move a Virtual Machine to a Different Datastore Using VMware vSphere Storage vMotion
You can migrate a virtual machine between datastores using the VMware Storage vMotion
feature of vCenter Server.
n Modify the Settings of the NIC Teaming Policy for a Virtual Switch
You can set the NIC teaming policy on a vSwitch. The NIC teaming policy determines the load
balancing and failover settings of a virtual switch and lets you mark NICs as unused.
VMware, Inc. 34
VMware PowerCLI User's Guide
VMware, Inc. 35
VMware PowerCLI User's Guide
n Modify the CPU Levels of a Virtual Machine with Get–View and Get–VIObjectByVIView
You can modify the CPU levels of a virtual machine using a combination of the Get-View and
Get-VIObjectByVIView cmdlets.
VMware, Inc. 36
VMware PowerCLI User's Guide
n Using Tags
You can assign tags to different types of objects, such as virtual machines, resource pools,
datastores, and vSphere distributed switches. You can use tags to retrieve a specific group of
objects.
VMware, Inc. 37
VMware PowerCLI User's Guide
n Managing Certificates
You can use VMware PowerCLI to manage certificates for both vCenter Server and ESXi no
matter if you are using Hybrid, Subordinate CA, or Full Custom Mode.
You can have more than one connection to the same server. For more information, see Managing
Default Server Connections.
If your login credentials contain non-alphanumeric characters, you might need to escape them.
For more information, see Providing Login Credentials.
Prerequisites
n If the certificate of the server you want to connect to is not trusted, verify that your PowerCLI
invalid server certificate action settings are configured properly. For more information, see
Configuring PowerCLI Response to Untrusted Certificates.
n If you use a proxy server for the connection, verify that it is configured properly, so that the
connection is kept alive long enough for tasks to finish.
Note If you do not want to use a proxy server for the connection, run Set-
PowerCLIConfiguration -ProxyPolicy NoProxy.
Procedure
VMware, Inc. 38
VMware PowerCLI User's Guide
You can authenticate to a federated vCenter Server by creating a new OAuth security context
and then exchanging it for a SAML security context. You create an OAuth security context for
PowerCLI by using the New-OAuthSecurityContext cmdlet. One way to do this is to authenticate
through the Authorization Code grant type, which is illustrated by this example. This workflow
guarantees a substantial degree of security and can be used with multi-factor authentication.
Note You can use PowerCLI to authenticate with the other OAuth 2.0 grant types as well, such
as the Client Credentials, Refresh Token, and Password grant types. For more information, run
Get-Help New-OAuthSecurityContext -full.
Prerequisites
n Verify that your vCenter Server system is federted to AD FS. For more information, see
Federate vCenter Server to Active Directory Federation Services (AD FS) in the VMware
vCenter Server Management Programming Guide.
n Create an OAuth client for PowerCLI on the authentication server (AD FS). Configure the
OAuth client to do the same token transformation as your vCenter Server system . You
must configure a redirect URL according to the requirements in the procedure below. Save
the Client ID and Client Secret that are generated by the authentication server. For more
information, see the Microsoft documentation.
Procedure
TokenEndpointUrl The base URL where the authentication server listens for https://<AD
requests to issue access tokens. You can see this value in the FS FQDN>/adfs/
openid-configuration file of the authentication server under oauth2/token/
token_endpoint key.
AuthorizationEndpointUrl The base URL at the authentication server where users https://<AD
are redirected in order to authenticate. You can see FS FQDN>/adfs/
this value in the openid-configuration file under the oauth2/authorize/
authorization_endpoint key.
VMware, Inc. 39
VMware PowerCLI User's Guide
RedirectUrl The URL where the user is redirected after he approves the http://
authentication request. This URL must be on a localhost and localhost:8844/auth
a free port on the machine where PowerCLI is running. This
URL must use the http schema.
ClientId The ID that you received from the authentication server when powercli-native
you registered the client application.
OtherArguments A hashtable of (String, String) pairs that represent arguments { "resource" = "my-
to the server-specific parameters. In the following example, vcenter" }
it is used for an AD FS Application Group for vCenter Server
with an example ID "my-vcenter".
3 Connect to your vCenter Server system by using the SAML security context.
Procedure
Get-VM
2 Save the name and the power state properties of the virtual machines in the ResourcePool
resource pool into a file named myVMProperties.txt.
Get-VM VM | Start-VM
Get-VMGuest VM | fc
Stop-VMGuest VM
VMware, Inc. 40
VMware PowerCLI User's Guide
Stop-VM VM
7 Move the virtual machine VM from the Host01 host to the Host02 host.
Note If the virtual machine you want to move across hosts is powered on, it must be located
on a shared storage registered as a datastore on both the original and the new host.
Prerequisites
Procedure
1 View all hosts on the vCenter Server system that you have established a connection with.
Get-VMHost
Add-VMHost -Name Host -Location (Get-Datacenter DC) -User root -Password pass
Prerequisites
Procedure
VMware, Inc. 41
VMware PowerCLI User's Guide
Prerequisites
Procedure
2 Get the cluster to which Host belongs and save the cluster object as a variable.
3 Start a task that activates maintenance mode for the Host host and save the task object as a
variable.
Note If the host is not automated or is partially automated and has powered-on virtual
machines running on it, you must use the RunAsync parameter and wait until all powered-on
virtual machines are relocated or powered off before applying DRS recommendations.
VMware, Inc. 42
VMware PowerCLI User's Guide
Prerequisites
Procedure
1 Get the inventory root folder and create a new folder named Folder in it.
Distributed Resource Scheduler (DRS) is a feature that provides automatic allocation of cluster
resources.
5 Add a host in the cluster by using the Add-VMHost command, and provide credentials when
prompted.
$vmCreationTask = New-VM -Name VM2 -VMHost $vmhost1 -ResourcePool MyRP01 -DiskGB 100
-MemoryGB 2 -RunAsync
The RunAsync parameter indicates that the command runs asynchronously. This means that
in contrast to a synchronous operation, you do not have to wait for the process to complete
before supplying the next command at the command line.
VMware, Inc. 43
VMware PowerCLI User's Guide
Prerequisites
<CreateVM>
<VM>
<Name>MyVM1</Name>
<HDDCapacity>100</HDDCapacity>
</VM>
<VM>
<Name>MyVM2</Name>
<HDDCapacity>100</HDDCapacity>
</VM>
</CreateVM>
Procedure
Note A virtual machine template is a reusable image created from a virtual machine. The
template, as a derivative of the source virtual machine, includes virtual hardware components,
an installed guest operating system, and software applications.
Prerequisites
VMware, Inc. 44
VMware PowerCLI User's Guide
Procedure
2 Convert the VM1Template template for use by a virtual machine named VM3.
Note A snapshot captures the memory, disk, and settings state of a virtual machine at a particular
moment. When you revert to a snapshot, you return all these items to the state they were in at the
time you took that snapshot.
Prerequisites
Procedure
The Location parameter takes arguments of the VIContainer type, on which Cluster,
Datacenter, Folder, ResourcePool, and VMHost object types are based. Therefore, the
Location parameter can use arguments of all these types.
VMware, Inc. 45
VMware PowerCLI User's Guide
2 Revert all virtual machines in the MyRP01 resource pool to the InitialSnapshot snapshot.
Prerequisites
Procedure
Prerequisites
VMware, Inc. 46
VMware PowerCLI User's Guide
Procedure
3 View the Name and the OverallStatus properties of the hosts in the DC data center.
4 View all hosts and their properties, and save the results to a file.
5 View a list of the hosts that are in maintenance mode and can be configured for vMotion
operations.
Prerequisites
Procedure
2 Enable creation of a checksum of the virtual machines memory during the migration.
VMware, Inc. 47
VMware PowerCLI User's Guide
Note You can use vSphere vMotion to move a powered-on virtual machine from one host to
another.
Prerequisites
The virtual machine must be stored on a datastore shared by the current and the destination host,
and the vMotion interfaces on the two hosts must be configured.
Procedure
u Get the VM1 virtual machine and move it to a host named ESXHost2.
Note You can use Storage vMotion to move a powered-on virtual machine from one datastore to
another.
Prerequisites
The host on which the virtual machine is running must have access both to the datastore where the
virtual machine is located and to the destination datastore.
Procedure
u Get the VM1 virtual machine and move it to a datastore named DS2:
VMware, Inc. 48
VMware PowerCLI User's Guide
You can move virtual machines between vCenter Server systems of vSphere version 6.0 and later
by using the Move-VM cmdlet. When you move a virtual machine from one vCenter Server system
to another, only datastores are supported as storage destinations.
Procedure
3 Store the MyVM virtual machine, its network adapters, the destination host, port group, and
datastore in variables.
4 Migrate the virtual machine to the specified destination host and datastore and attach the
virtual machine network adapters to the destination port group.
Prerequisites
Verify that you are connected to a host that runs vCenter Server 4.1 or later.
Procedure
1 Get the host named Host1 and store it in the $vmhost variable.
VMware, Inc. 49
VMware PowerCLI User's Guide
Set-VMHostProfile -Profile $hp1 -Description "This is my old test host profile based on
Host1."
Prerequisites
Verify that you are connected to a host that runs vCenter Server 4.1 or later.
Procedure
3 Verify that the Host2 host is compliant with the HostProfile1 profile.
The output of this command contains the incompliant settings of the host, if any.
The $neededVariables variable contains the names of all required variables and their default
or current values, as returned by the server. Otherwise, the $neededVariables variable
contains the name of the host on which the profile has been applied.
VMware, Inc. 50
VMware PowerCLI User's Guide
You can modify the properties of a statistics interval and view statistics for a selected cluster.
Prerequisites
Procedure
1 Increase the amount of time for which statistics of the previous day are stored.
2 View the available memory metric types for the Cluster1 cluster.
Prerequisites
Procedure
1 Get a list of the physical NIC objects on the host network and store them in a variable.
2 Store the physical NIC objects you want to mark as unused in separate variables.
$pn5 = $pn.PhysicalNic[2]
$pn6 = $pn.PhysicalNic[3]
$pn7 = $pn.PhysicalNic[0]
VMware, Inc. 51
VMware PowerCLI User's Guide
4 Change the policy of the switch to indicate that the $pn5, $pn6, and $pn7 network adapters
are unused.
5 Modify the load balancing and failover settings of the virtual switch NIC teaming policy.
Prerequisites
Procedure
New-VApp -Name VApp -CpuLimitMhz 4000 -CpuReservationMhz 1000 -Location (Get-VMHost Host1)
Start-VApp VApp
Prerequisites
Procedure
VMware, Inc. 52
VMware PowerCLI User's Guide
Prerequisites
Procedure
2 Export the OldVApp vApp to a local directory and name the exported appliance WebApp.
3 Import the WebApp vApp from a local directory to the Storage2 datastore.
Prerequisites
Procedure
VMware, Inc. 53
VMware PowerCLI User's Guide
You can provide the LUN path by using its canonical name beginning with the device name of
the iSCSI HBA.
Prerequisites
Procedure
$vm = Get-VM VM
Get-PassthroughDevice -VM $vm -Type Scsi
Prerequisites
VMware, Inc. 54
VMware PowerCLI User's Guide
Procedure
Results
You have created a custom property named ToolsVersion for VirtualMachine objects.
Prerequisites
Procedure
1 Create a new custom property named NameOfHost that stores the name of the host on which
a virtual machine resides.
Results
You created a custom script property named NameOfHost for VirtualMachine objects.
Prerequisites
VMware, Inc. 55
VMware PowerCLI User's Guide
Procedure
1 Get the Spec customization specification and clone it for temporary use.
2 Change the NamingPrefix property of the customization object to the name of the virtual
machine you want to create.
3 Create a virtual machine named VM1 by cloning the existing VM virtual machine and applying
the customization specification.
Procedure
Each customization specification object has one default NIC mapping object.
3 Modify the default NIC mapping object of the Spec customization specification to use static IP.
4 Create a new virtual machine named VM1 from a template, and apply the static IP settings.
New-VM -Name VM1 -VMHost Host -Datastore Storage1 -OSCustomizationSpec Spec -Template
Template
VMware, Inc. 56
VMware PowerCLI User's Guide
Procedure
Get-NetworkAdapter VM
When you apply a customization specification, each network adapter of the customized virtual
machine must have a corresponding NIC mapping object. You can correlate network adapters
and NIC mapping objects either by their position numbers, or by MAC address.
4 View the NIC mapping objects and verify that two NIC mapping objects are available.
The default NIC mapping object is DHCP enabled, and the newly added one uses a static IP
address.
6 Associate a network adapter from the VMNetwork network with the NIC mapping object that
uses DHCP mode.
VMware, Inc. 57
VMware PowerCLI User's Guide
Prerequisites
Verify that you have defined a list of static IP addresses in a CSV file.
Procedure
$vmNameTemplate = "VM-{0:D3}"
2 Save the cluster in which the virtual machines should be created into a variable.
3 Save the template on which the virtual machines should be based into a variable.
$vmList = @()
5 Save the static IP addresses from the stored CSV file into a variable.
# The specification has a default NIC mapping – retrieve it and update it with the
static IP
$nicMapping = Get-OSCustomizationNicMapping –OSCustomizationSpec $specClone
$nicMapping | Set-OSCustomizationNicMapping –IpMode UseStaticIP –IpAddress $ip –
SubnetMask "255.255.252.0" –DefaultGateway "192.168.0.1"
VMware, Inc. 58
VMware PowerCLI User's Guide
You can configure each virtual machine to have one network adapter attached to a public network
and one network adapter attached to a private network. You can configure the network adapters
on the public network to use static IP addresses and the network adapters on the private network
to use DHCP.
Prerequisites
Verify that you have defined a list of static IP addresses in a CSV file.
Procedure
$vmNameTemplate = "VM-{0:D3}"
2 Save the cluster in which the virtual machines should be created into a variable.
3 Save the template on which the virtual machines should be based into a variable.
$vmList = @()
5 Save the static IP addresses from the stored CSV file into a variable.
VMware, Inc. 59
VMware PowerCLI User's Guide
# Retrieve the virtual machine’s network adapter attached to the public network named
"Public"
$publicNIC = $vmList[$i] | Get-NetworkAdapter | where {$_.NetworkName -eq "Public"}
# Retrieve the virtual machine’s network adapter attached to the private network named
"Private"
$privateNIC = $vmList[$i] | Get-NetworkAdapter | where {$_.NetworkName -eq "Private"}
# Create a NIC mapping for the "Public" NIC that should use static IP
$linuxSpec | New-OSCustomizationNicMapping –IpMode UseStaticIP –IpAddress
$ip –SubnetMask "255.255.252.0" –DefaultGateway "192.168.0.1" –NetworkAdapterMac
$publicNIC.MacAddress
# Create a NIC mapping for the "Private" NIC that should use DHCP
$linuxSpec | New-OSCustomizationNicMapping –IpMode UseDhcp –NetworkAdapterMac
$privateNIC.MacAddress
Note vSphere permissions determine your level of access to vCenter Server, and ESXi hosts.
Privileges define individual rights to perform actions and access object properties. Roles are
predefined sets of privileges.
Prerequisites
Procedure
VMware, Inc. 60
VMware PowerCLI User's Guide
The Principal parameter accepts both local and domain users and groups if the vCenter
Server system is joined in AD.
Results
Prerequisites
Procedure
1 Get all PowerCLI supported alarm actions for the Host Processor Status alarm.
2 Get all the triggers for the first alarm definition found.
Prerequisites
VMware, Inc. 61
VMware PowerCLI User's Guide
Procedure
Prerequisites
Procedure
1 For all host alarms, modify the interval after the action repeats.
2 Modify the name and the description of a selected alarm definition, and enable the alarm.
Prerequisites
VMware, Inc. 62
VMware PowerCLI User's Guide
Procedure
Prerequisites
Procedure
VMware, Inc. 63
VMware PowerCLI User's Guide
Prerequisites
Procedure
3 Modify the value of the advanced setting stored in the $setting2 variable.
The ` character is used to escape the wildcard characters [ and ] in the advanced setting name.
Prerequisites
Procedure
1 View the current email configuration settings of the vCenter Server from the $srv variable.
VMware, Inc. 64
VMware PowerCLI User's Guide
Prerequisites
Procedure
1 View the current SNMP configuration settings of the vCenter Server from the $srv variable.
Results
Prerequisites
Verify that you are connected to a server that runs ESX 4.1, vCenter Server 5.0 or later.
Procedure
1 Get the group to which the virtual machine belongs and save it as a variable.
VMware, Inc. 65
VMware PowerCLI User's Guide
2 Get the IDs of all virtual CPUs of the virtual machine and store them in an array.
4 Calculate the used and ready for use percentage by using the UsedTimeInUsec and
ReadyTimeInUsec stats.
$result = @()
$cpuStats | %{ `
$row = "" | select VCPUID, Used, Ready; `
$row.VCPUID = $_.VCPUID; `
$row.Used = [math]::Round(([double]$_.UsedTimeInUsec/[double]$_.UpTimeInUsec)*100, 2); `
$row.Ready = [math]::Round(([double]$_.ReadyTimeInUsec/[double]$_.UpTimeInUsec)*100, 2);`
$result += $row
}
5 View the used and ready for use percentage for each virtual CPU of the virtual machine.
The filter parameter is a HashTable object 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.
Prerequisites
Procedure
1 Create a filter by the power state and the guest operating system name of the virtual
machines.
2 Get a list of the virtual machines by using the created filter and call the ShutdownGuest method
for each virtual machine in the list.
VMware, Inc. 66
VMware PowerCLI User's Guide
Results
The filter gets a list of the powered-on virtual machines whose guest OS names contain the string
Windows XP. The Get-View cmdlet then initiates shutdown for each guest operating system in the
list.
Prerequisites
Procedure
$vmhostView.Summary.Runtime
Prerequisites
Procedure
$vm2.Runtime.PowerState
VMware, Inc. 67
VMware PowerCLI User's Guide
$vm2.Runtime.PowerState
The power state is not updated yet because the virtual machine property values are not
updated automatically.
$vm2.UpdateViewData()
$vm2.Runtime.PowerState
Prerequisites
Procedure
1 Use the Get-VMHost cmdlet to get a host by its name, and pass the result to the Get-View
cmdlet to get the corresponding view object.
2 Call the reboot method of the host view object to reboot the host.
$vmhostView.RebootHost()
VMware, Inc. 68
VMware PowerCLI User's Guide
Prerequisites
Procedure
1 Get the VM2 virtual machine, shut it down, and pass it to the Get-View cmdlet to view the
virtual machine view object.
2 Create a VirtualMachineConfigSpec object to modify the virtual machine CPU levels and call
the ReconfigVM method of the virtual machine view managed object.
3 Get the virtual machine object by using the Get-VIObjectByVIView cmdlet and start the
virtual machine.
Note For more information about the Inventory Provider and the default inventory drive, see
PowerCLI Inventory Provider.
Prerequisites
Procedure
cd vi:
dir
VMware, Inc. 69
VMware PowerCLI User's Guide
Prerequisites
Procedure
Note You can use the New-InventoryDrive cmdlet, which is an alias of New-PSDrive.
This cmdlet creates a new inventory drive using the Name and Datastore parameters. For
example: Get-Folder -NoRecursion | New-VIInventoryDrive -Name myVi.
Prerequisites
Procedure
1 Navigate to a host in your server inventory by running the cd command with the full path to
the host.
cd Folder01\DataCenter01\host\Web\Host01
ls
This command returns the virtual machines and the root resource pool of the host.
VMware, Inc. 70
VMware PowerCLI User's Guide
Get-VM
When called within the inventory drive, Get-VM gets a list only of the virtual machines on the
current drive location.
del VM1
6 Start all virtual machines with names that start with VM.
Note For more information about default datastore drives, see PowerCLI Datastore Provider.
Prerequisites
Procedure
cd vmstore:
dir
Prerequisites
VMware, Inc. 71
VMware PowerCLI User's Guide
Procedure
Note You can use the New-PSDrive cmdlet, which is an alias of New-DatastoreDrive.
It creates a new datastore drive using the Name and Datastore parameters. For example:
Get-Datastore Storage1 | New-DatastoreDrive -Name ds.
Prerequisites
Procedure
cd VirtualMachines\XPVirtualMachine
ls
For example, to change the name of the vmware-3.log file to vmware-3old.log, run:
For example, to remove the vmware-3old.log file from the XPVirtualMachine folder, run:
del ds:\VirtualMachines\XPVirtualMachine\vmware-2.log
VMware, Inc. 72
VMware PowerCLI User's Guide
6 Copy a file to another datastore by running the Copy-Item cmdlet or its alias copy.
copy ds:\Datacenter01\Datastore01\XPVirtualMachine\vmware-1.log
ds:\Datacenter01\Datastore02\XPVirtualMachine02\vmware.log
7 Create a new folder by running the New-Item cmdlet or its alias mkdir.
8 Download a file from the datastore drive to the local machine by running the Copy-
DatastoreItem cmdlet.
9 Upload a file from the local machine by running the Copy-DatastoreItem cmdlet.
Copy-DatastoreItem C:\Temp\vmware-3.log
ds:\VirtualMachines\XPVirtualMachine\vmware-3new.log
Prerequisites
Procedure
1 (Optional) Learn more about what settings you can configure with Set-
PowerCLIConfiguration.
Get-Help Set-PowerCLIConfiguration
2 Store the value of the timeout setting for the current session in the $initialTimeout variable.
VMware, Inc. 73
VMware PowerCLI User's Guide
$arguments = $esxcli.software.profile.install.CreateArgs()
$arguments.depot = "http://mysite.com/publish/proj/index.xml"
$arguments.profile = "proj-version"
$esxcli.software.profile.install.Invoke($arguments)
n Alternatively, you can directly specify the arguments hash table in-line.
5 Revert the timeout setting for the current session to the initial value.
Using Tags
You can assign tags to different types of objects, such as virtual machines, resource pools,
datastores, and vSphere distributed switches. You can use tags to retrieve a specific group of
objects.
Prerequisites
Procedure
Prerequisites
VMware, Inc. 74
VMware PowerCLI User's Guide
Procedure
Prerequisites
Procedure
Prerequisites
Procedure
VMware, Inc. 75
VMware PowerCLI User's Guide
Prerequisites
Procedure
Note You can only specify a tag filter parameter for the VM, VMHost, Datastore, and
VirtualPortGroup object types.
You must use the Get-VIAccount cmdlet to retrieve user accounts. For more information, see the
documentation of the cmdlet.
Prerequisites
n Verify that the user accounts and the vCenter Server system are in the same domain.
Procedure
1 Create a new tag category and specify that tags in this category can only be assigned to
entities of type VirtualMachine.
Note If you do not specify an entity type, tags from this category can be assigned to all entity
types.
4 Retrieve a specific tag from the Owner category, so that you can later assign it to a specific
virtual machine.
VMware, Inc. 76
VMware PowerCLI User's Guide
Prerequisites
Procedure
Prerequisites
Procedure
1 Retrieve all virtual machines that have a tag from the ownerTagCategory tag category
assigned to them.
Prerequisites
VMware, Inc. 77
VMware PowerCLI User's Guide
Procedure
1 Get the data center where you want to create the vSphere distributed switch.
6 Add the physical network adapter to the distributed switch that you created.
7 Create a new distributed port group with 1000 ports and add it to the distributed switch.
8 Connect all virtual machines running on the hosts in your data center to the distributed port
group.
What to do next
Adjust the settings of the distributed switch. See Configure a Distributed Switch.
Prerequisites
VMware, Inc. 78
VMware PowerCLI User's Guide
Procedure
Prerequisites
Procedure
1 Get the source vSphere standard switch from which you want to migrate the virtual machine
networking.
2 Get the source standard port group to which the virtual machines are connected.
3 Get the target vSphere distributed switch to which you want to migrate the virtual machine
networking.
4 Get the target port group to which you want to connect the virtual machines.
VMware, Inc. 79
VMware PowerCLI User's Guide
5 Get the virtual machine network adapters connected to the source port group.
6 Disconnect the retrieved network adapters from the standard port group and connect them to
the distributed port group.
Prerequisites
Procedure
3 Get the vSphere standard switch to which you want to migrate the network adapters.
Prerequisites
VMware, Inc. 80
VMware PowerCLI User's Guide
Procedure
3 Get the port groups corresponding to the virtual network adapters that you want to migrate to
the vSphere distributed switch.
Results
You migrated the $vNicManagement network adapter to the Management Network port group
and the $vNicvMotion network adapter to the vMotion Network port group.
Prerequisites
Procedure
VMware, Inc. 81
VMware PowerCLI User's Guide
Prerequisites
Procedure
Prerequisites
Procedure
1 Get the datastore that you want to use to store files for library items in this library.
2 Create the My Local Content Library published local content library that uses the myDatastore
datastore.
New-ContentLibrary -Name 'My Local Content Library' -Description 'Local content library
description.' -Datastore $Datastore1 -Published
Prerequisites
Procedure
u Create the My Subscribed Content Library subscribed content library that uses the
myDatastore datastore.
VMware, Inc. 82
VMware PowerCLI User's Guide
Prerequisites
Procedure
1 Get the files that you want to upload to the content library.
Note VMware PowerCLI cannot distinguish between OVF content library items of type virtual
machine template and vApp template. As a result, New-VM creates a vApp if you specify a vApp
template from the content library by using the ContentLibraryItem parameter of the cmdlet. If
this happens, New-VM returns an error, notifying that the cmdlet produced an inventory item of the
wrong type. Avoid creating vApps by using the New-VM cmdlet, as this behavior will be deprecated
in future releases.
Prerequisites
n Verify that you have a content library with virtual machine templates available.
Procedure
2 Create the MyVM virtual machine from the MyVMContentLibrayItemName content library item.
VMware, Inc. 83
VMware PowerCLI User's Guide
Note VMware PowerCLI cannot distinguish between OVF content library items of type virtual
machine template and vApp template. As a result, New-VApp creates a virtual machine if you
specify a virtual machine template from the content library by using the ContentLibraryItem
parameter of the cmdlet. If this happens, New-VApp returns an error, notifying that the cmdlet
produced an inventory item of the wrong type. Avoid creating virtual machines by using the
New-VApp cmdlet, as this behavior will be deprecated in future releases.
Prerequisites
n Verify that you have a content library with vApp templates available.
Procedure
2 Create the MyVApp vApp from the MyVAppContentLibrayItemName content library item.
Prerequisites
Procedure
VMware, Inc. 84
VMware PowerCLI User's Guide
Prerequisites
n Verify that virtual machines and hosts exist within a cluster with enabled DRS in the vCenter
Server environment.
Procedure
Prerequisites
n Verify that virtual machines and hosts exist within a cluster with enabled DRS in the vCenter
Server environment.
Procedure
VMware, Inc. 85
VMware PowerCLI User's Guide
6 Create the VM-VMHost DRS rule by using the newly created VM DRS cluster group and
VMHost DRS cluster group.
Managing Certificates
You can use VMware PowerCLI to manage certificates for both vCenter Server and ESXi no matter
if you are using Hybrid, Subordinate CA, or Full Custom Mode.
Starting from VMware PowerCLI 12.4.0, you can do various certificate management operations
in your vSphere environment. The certificate management functionality is included in the
VMware.PowerCLI.VCenter module.
Prerequisites
n Verify that the root certificate or certificate chain you want to add is available on your machine.
Procedure
1 (Optional) List the trusted root certificates on your vCenter Server system and the connected
ESXi hosts.
Get-VITrustedCertificate
2 Create a variable with the root certificate or certificate chain you want to add.
3 Add the root certificate or certificate chain to vCenter Server and to the connected ESXi hosts
4 (Optional) Verify that your new root certificate or certificate chain has been added to the
trusted certificate stores.
Get-VITrustedCertificate
VMware, Inc. 86
VMware PowerCLI User's Guide
Prerequisites
n Verify that the root certificate of the CA you are going to use is added to the trusted root store
of vCenter Server.
Procedure
1 (Optional) Retrieve the current Machine SSL certificate of the vCenter Server system.
Get-VIMachineCertificate -VCenterOnly
2 Generate a CSR.
$csrParams = @{
Country="US"
Email="[email protected]"
Locality="San Francisco"
Organization="My Company"
OrganizationUnit="PowerCLI"
StateOrProvince="California"
}
$csr = New-VIMachineCertificateSigningRequest @csrParams
Important The change of the Machine SSL certificate triggers a restart of vCenter Server.
Wait for the system to reboot and login when available.
VMware, Inc. 87
VMware PowerCLI User's Guide
Prerequisites
n Verify that the root certificate of the CA you are going to use is added to the trusted root store
of vCenter Server and to the connected ESXi hosts.
Procedure
2 In the vCenter Server system, retrieve the setting for the ESXi host certificate management
mode.
4 For the new certificate management mode to take effect, reboot your vCenter Server system.
$esxRequest = New-VIMachineCertificateSigningRequest `
-VMHost $vmhost `
-Country "US" `
-Locality "San Francisco" `
-Organization "My Company" `
-OrganizationUnit "PowerCLI" `
-StateOrProvince "California" `
-CommonName <ESXi host's FQDN> or <ESXi host's IP address>
Note For CommonName, you must use either the ESXi host's FQDN or IP address. The
common name must match the identifier you use to add the host to the vCenter Server system.
VMware, Inc. 88
VMware PowerCLI User's Guide
Remove-VMHost $vmhost
Disconnect-VIServer $vCenterConnection
Restart-VMHost $targetEsxHost
Disconnect-VIServer $esxConnection
VMware, Inc. 89
VMware PowerCLI User's Guide
21 (Optional) Verify that the Machine SSL certificate of the ESXi host is changed.
VMware, Inc. 90
Managing vSphere Policy-Based
Storage with VMware PowerCLI 6
To help you get started with VMware PowerCLI, this documentation provides a set of sample
scripts that illustrate basic and advanced tasks in vSphere policy-based storage management.
n Associate a Storage Policy with a Virtual Machine and Its Hard Disk
n Disassociate a Storage Policy Associated with a Virtual Machine and Its Hard Disk
VMware, Inc. 91
VMware PowerCLI User's Guide
Prerequisites
n Verify that a tag named Tag1 exists in the vCenter Server environment.
Procedure
2 Create a rule with the $tag tag and store the rule in the $rule variable.
3 Create a rule set by using the $rule rule and store the rule set in the $ruleset variable.
4 Create a tag-based policy named Tag-Based-Policy by using the $ruleset rule set and store
the policy in the $policy variable.
Prerequisites
n Verify that a storage provider is registered with the vCenter Server system.
Procedure
2 Create a rule with the $cap capability and store the rule in the $rule variable.
3 Create a rule set by using the $rule rule and store the rule set in the $ruleset variable.
VMware, Inc. 92
VMware PowerCLI User's Guide
4 Create a capability-based policy named Capability-Based-Policy by using the $ruleset rule set
and store the policy in the $policy variable.
Prerequisites
n Verify that a storage policy named Str-Policy exists in the vCenter Server environment.
n Verify that a virtual machine named Target-VM exists in the vCenter Server environment.
Procedure
1 Get the Str-Policy storage policy and store it in the $policy variable.
2 Get the Target-VM virtual machine and store it in the $vm variable.
3 Get the hard disk associated with the $vm virtual machine and store it in the $hd variable.
4 Assign the $policy storage policy to the $vm virtual machine and the $hd hard disk.
5 View the $policy storage policy's compliance with the $vm virtual machine and the $hd hard
disk.
Note The storage policy can be compliant only if the datastore on which the virtual machine
and hard disk are created is compliant with the storage policy.
VMware, Inc. 93
VMware PowerCLI User's Guide
Prerequisites
n Verify that a virtual machine named Target-VM exists in the vCenter Server environment.
n Verify that a storage policy is associated with the Target-VM virtual machine.
Procedure
1 Get the Target-VM virtual machine and store it in the $vm variable.
2 Get the hard disk associated with the $vm virtual machine and store it in the $hd variable.
3 Disassociate all storage policies that are associated with the $vm virtual machine and the $hd
hard disk.
Prerequisites
n Verify that a storage policy named pol-tag exists in the vCenter Server environment.
Procedure
1 Get the pol-tag storage policy and store it in the $policy variable.
VMware, Inc. 94
VMware PowerCLI User's Guide
Prerequisites
n Verify that a storage provider is registered with the vCenter Server system.
n Verify that a storage policy named pol-tag exists in the vCenter Server environment.
Procedure
1 Get the pol-tag storage policy and store it in the $policy variable.
3 Create a new rule set by using the $newRule rule and store it in the $newRuleset variable.
4 Modify the $policy storage policy by replacing the existing rule set with the newly created
$newRuleset rule set.
Prerequisites
n Verify that you have read-write permissions for the directory in which the storage policy is
saved.
VMware, Inc. 95
VMware PowerCLI User's Guide
n Verify that a storage policy named pol-tag exists in the vCenter Server environment.
Procedure
Prerequisites
n Verify that a tag-based storage policy named Tag-Policy exists in the vCenter Server
environment.
n Verify that the tag of the Tag-Policy storage policy is associated with one of the available
datastores in the vCenter Server environment.
Procedure
1 Get the tag-based Tag-Policy storage policy and store it in the $policy variable.
2 Get the tag used in the Tag-Policy storage policy and store it in the $tag variable.
$tag = ($($($policy.AnyOfRulesets).AllOfRules).AnyOfTags)[0]
3 Get a datastore compatible with the $policy storage policy and store it in the $ds variable.
4 Get the virtual machine host that contains the $ds datastore and store it in the $vmhost
variable.
VMware, Inc. 96
VMware PowerCLI User's Guide
5 Create a virtual machine named VM-Tag in the $ds datastore and store the virtual machine
object in the $vm variable.
$vm = New-VM -Name 'VM-Tag' -ResourcePool $vmHost -Datastore $ds -NumCPU 2 -MemoryGB 4
-DiskMB 1
6 Associate the $policy storage policy with the $vm virtual machine.
7 Verify that the $vm virtual machine is compliant with the $policy storage policy.
Get-SpbmEntityConfiguration $vm
8 Get the Tag-Assignment object for the $ds datastore and store it in the $tagAs variable.
10 Check the compliance of the $vm virtual machine with the $policy storage policy.
Get-SpbmEntityConfiguration $vm
Prerequisites
n Verify that you have access to at least three virtual machine hosts.
n Verify that each of the virtual machine hosts has at least one SSD and one HDD.
Procedure
VMware, Inc. 97
VMware PowerCLI User's Guide
4 Add each of the three hosts to the vSAN cluster to create a vSAN datastore.
8 Assign the storage policy to the virtual machine and its hard disk.
9 Check the compliance of the virtual machine and its hard disk with the storage policy.
VMware, Inc. 98
VMware PowerCLI User's Guide
Prerequisites
n Verify that at least one vSAN disk group exists in the cluster.
Procedure
$dg = $dgs[0]
Get-VsanDisk –VsanDiskGroup $dg
Prerequisites
n Verify that you have access to at least two virtual machine hosts.
n Verify that each of the virtual machine hosts has at least one SSD and one HDD.
n Verify that you have access to an ESXi host that can be used as a witness host or deploy a
witness appliance on any node. Ensure that the witness host or appliance is outside the vSAN
cluster.
VMware, Inc. 99
VMware PowerCLI User's Guide
Procedure
3 Add the two hosts to the vSAN cluster to create a vSAN datastore.
Prerequisites
Procedure
1 Add a vSAN file service OVF to the OVF repository of the vCenter Server system.
Add-VsanFileServiceOvf
Get-VsanFileServiceOvfInfo
3 Increase the PowerCLI timeout for the current session, so that the operation does not stop.
4 Retrieve the network that you want to use for the vSAN file service.
5 Modify the vSAN cluster configuration that you want to use to enable the vSAN file service.
$config = Get-VsanClusterConfiguration
Set-VsanClusterConfiguration $config -FileServiceEnabled $true -FileServiceNetwork $net
Prerequisites
Procedure
1 Configure a vSAN file server IP configuration. You can use the IPs as an IP pool for the file
service domain.
Prerequisites
Procedure
Prerequisites
n Verify that the remote NFS share supports multipathing and Kerberos authentication.
Procedure
1 Get the virtual machine host where you want to create the NFS 4.1 datastore.
3 Set a DNS server and search the domain for the virtual machine host.
5 Create an NFS user on the virtual machine host for Kerberos-based authentication for the NFS
4.1 datastore.
9 (Optional) Get the NFS user from the virtual machine host.
Prerequisites
Procedure
Get-SpbmCapability
3 Create a new SPBM rule with the exposed capabilities of the registered VASA provider.
6 Refresh the VASA provider registered with the vCenter Server system.
8 Refresh the VASA provider registered with the vCenter Server system.
9 Get the VASA provider registered with the vCenter Server system.
Prerequisites
n Verify that you are connected to the vCenter Server systems of the source and target sites.
n Verify that you have access to at least one virtual machine host on each site.
n Verify that you have registered a Virtual Volume VASA provider and have access to a Virtual
Volume datastore on each site.
Procedure
2 Get a datastore compatible with the created replication storage policy and store it in the $ds
variable.
3 Create a virtual machine named MyVM with a hard disk in the $ds datastore.
$vm = New-VM -Name 'MyVM' -VMHost 'Host-Source' -DiskMB 512 -Datastore $ds
$hd = Get-HardDisk -VM $vm
4 Get a replication group for the $ds datastore and the $replicationPolicy storage policy, and
store the replication group in the $rg variable.
5 Associate the $vm virtual machine and its hard disk with the $replicationPolicy storage policy,
and put them in the $rg replication group.
6 Check the compliance of the $vm virtual machine and $hd hard disk with the
$replicationPolicy storage policy.
7 Get the replication pair corresponding to the $rg source replication group, and store that pair
in the $rgPair variable.
Sync-SpbmReplicationGroup $rgPair.Target
Stop-VM $vm
Remove-VM $vm
Start-SpbmReplicationPrepareFailover $rgPair.Source
11 Synchronize the target replication group again, to get the latest state of the source devices.
Sync-SpbmReplicationGroup $rgPair.Target
12 Invoke the planned failover on the source replication group and store the virtual machine file
path on the target site in the $vmFilePath variable.
13 Register the virtual machine on the Host-Target host and power on the virtual machine.
Start-SpbmReplicationReverse $rgPair.Target
Prerequisites
n Verify that you have access to at least one virtual machine host.
n Verify that there is at least one datastore mounted on the virtual machine host.
Procedure
1 Mount the datastore on the virtual machine host and store the datastore in the $ds variable.
2 Create a flat, thin-provisioned virtual disk with 2-GB capacity on the $ds datastore.
3 Create a virtual machine named VirtualMachine with one hard disk and store this virtual
machine in the $vm variable.
$vm = New-VM -Name 'VirtualMachine' -VMHost 'Host-A' -Datastore $ds -DiskMB 512
6 Verify that the VDisk object has been attached and the virtual machine now has two hard disks.
n Create a Report of the Virtual Machines Associated with All Protection Groups
Some of the objects returned by the SRM API are objects from the vSphere API. To use those
objects in integration with the vSphere API through PowerCLI, you can connect to the vCenter
Server system that the SRM server is registered with.
Prerequisites
n If the certificate of the server you want to connect to is not trusted, verify that your PowerCLI
invalid server certificate action settings are configured properly. For more information, see
Configuring PowerCLI Response to Untrusted Certificates.
n If you use a proxy server for the connection, verify that it is configured properly, so that the
connection is kept alive long enough for tasks to finish.
Note If you do not want to use a proxy server for the connection, run Set-
PowerCLIConfiguration -ProxyPolicy NoProxy.
Procedure
1 To connect to the vCenter Server system that the SRM server is registered with, run Connect-
VIServer with the server name and valid credentials.
2 To connect to the SRM server registered with the connected vCenter Server system, run
Connect-SrmServer.
$srmConnection = Connect-SrmServer
Note If you have previously connected to other vCenter Server systems configured with SRM
server support, this cmdlet invocation establishes a connection to their corresponding SRM
servers as well.
3 (Optional) To use the SRM API, you can call methods of the root object and instances of the
objects that those calls return.
$srmApi = $srmConnection.ExtensionData
Note The root SRM API object is the ExtensionData property of the SrmServer object.
Procedure
1 Connect to the vCenter Server system that the SRM server is registered with.
2 Establish a connection to the local SRM server by providing credentials to the remote SRM
site.
$srmApi = $srmConnection.ExtensionData
$protectionGroups = $srmApi.Protection.ListProtectionGroups()
4 Associate the TestVM virtual machine with the ProtGroup1 protection group and enable the
protection for that virtual machine.
$targetProtectionGroup.AssociateVms(@($vmToAdd.ExtensionData.MoRef))
VMware.VimAutomation.Srm.Views.SrmProtectionGroupVmProtectionSpec
$protectionSpec.Vm = $vmToAdd.ExtensionData.MoRef
$protectTask = $targetProtectionGroup.ProtectVms($protectionSpec)
while(-not $protectTask.IsComplete()) { sleep -Seconds 1 }
Prerequisites
Procedure
$srmApi = $srmConnection.ExtensionData
$protectionGroups = $srmApi.Protection.ListProtectionGroups()
$protectionGroups | % {
$protectionGroup = $_
$protectionGroupInfo = $protectionGroup.GetInfo()
# The following command lists the virtual machines associated with a protection group
$protectedVms = $protectionGroup.ListProtectedVms()
# The result of the above call is an array of references to the virtual machines at
the vSphere API
# To populate the data from the vSphere connection, call the UpdateViewData method on
each virtual machine view object
$protectedVms | % { $_.Vm.UpdateViewData() }
# After the data is populated, use it to generate a report
$protectedVms | %{
$output = "" | select VmName, PgName
$output.VmName = $_.Vm.Name
$output.PgName = $protectionGroupInfo.Name
$output
}
} | Format-Table @{Label="VM Name"; Expression={$_.VmName} }, @{Label="Protection group
name"; Expression={$_.PgName} }
Prerequisites
Procedure
$srmApi = $srmConnection.ExtensionData
$protectionGroups = $srmApi.Protection.ListProtectionGroups()
2 Generate a report of the virtual machines associated with all protection groups.
$protectionGroups | % {
$protectionGroup = $_
$protectionGroupInfo = $protectionGroup.GetInfo()
# The following command lists the virtual machines associated with a protection group
$vms = $protectionGroup.ListAssociatedVms()
# The result of the above call is an array of references to the virtual machines at
the vSphere API
# To populate the data from the vSphere connection, call the UpdateViewData method on
each virtual machine view object
$vms | % { $_.UpdateViewData() }
# After the data is populated, use it to generate a report
$vms | %{
$output = "" | select VmName, PgName
$output.VmName = $_.Name
$output.PgName = $protectionGroupInfo.Name
$output
}
} | Format-Table @{Label="VM Name"; Expression={$_.VmName} }, @{Label="Protection group
name"; Expression={$_.PgName} }
The vSphere Automation SDK is integrated in VMware PowerCLI, starting from version 12.4.0. The
modules that contain the vSphere Automation SDK start with the VMware.vSphere.Sdk prefix.
The vSphere Automation SDK functions on a low level and communicates directly with the
vSphere Automation API server. The results from the API operations are returned as PowerShell
custom objects.
You can construct vSphere Automation SDK cmdlets by using the Initialize- and Invoke-
cmdlet verbs in combination with the names of the API data structures or operations.
n Use the Initialize- cmdlets to prepare the data structures, if any, for your API calls. These
cmdlets function on the client side and do not communicate with the API server.
n Use the Invoke- cmdlets to call the vSphere Automation API server and invoke the operations.
You can access a vSphere Automation API server in two ways with PowerCLI.
You can have more than one connection to the same server. For more information, see Managing
Default Server Connections.
If your login credentials contain non-alphanumeric characters, you might need to escape them.
For more information, see Providing Login Credentials.
Prerequisites
n If the certificate of the server you want to connect to is not trusted, verify that your PowerCLI
invalid server certificate action settings are configured properly. For more information, see
Configuring PowerCLI Response to Untrusted Certificates.
n If you use a proxy server for the connection, verify that it is configured properly, so that the
connection is kept alive long enough for tasks to finish.
Note If you do not want to use a proxy server for the connection, run Set-
PowerCLIConfiguration -ProxyPolicy NoProxy.
Procedure
You can create a configuration object and pass information about the vCenter Server system on
which you want to use the vSphere Automation SDK for PowerShell. You can use this connection
method if you don't want to use the PowerCLI high-level cmdlets or if you don't have the
VMware.VimAutomation.Core module installed on your system.
Procedure
3 Update the server configuration with the created API session key.
What to do next
To learn more about using server configuration objects with the vSphere Automation SDK, see
Managing vCenter Server Connections Through Configuration Objects.
Cmdlet Description
If you want to apply the Invoke- cmdlets to a specific configuration object, you must specify it in
the command. For example,
Get-vSphereServerConfiguration
$serverConfig | Remove-vSphereServerConfiguration
Prerequisites
Procedure
Prerequisites
Procedure
Invoke-GetLocalAccountsGlobalPolicy
Invoke-GetLocalAccountsGlobalPolicy
Prerequisites
Procedure
Prerequisites
Procedure
2 Create a tag.
Prerequisites
Procedure
n Retrieve a List of the Internal and External IP Addresses of Virtual Machines in vApps
When managing vApps in the cloud, you might need to obtain information about the NIC
settings of the associated virtual machines.
You can have more than one connection to the same server. For more information, see Managing
Default Server Connections.
If your login credentials contain non-alphanumeric characters, you might need to escape them.
For more information, see Providing Login Credentials.
Prerequisites
n If the certificate of the server you want to connect to is not trusted, verify that your PowerCLI
invalid server certificate action settings are configured properly. For more information, see
Configuring PowerCLI Response to Untrusted Certificates.
n If you use a proxy server for the connection, verify that it is configured properly, so that the
connection is kept alive long enough for tasks to finish.
Note If you do not want to use a proxy server for the connection, run Set-
PowerCLIConfiguration -ProxyPolicy NoProxy.
Procedure
Prerequisites
Verify that you are connected to a VMware Cloud Director server as a provider administrator.
Procedure
2 Add a new organization on the server and provide a name and a full name for it.
By default, the new organization is enabled. Enabling the organization lets users log in.
Prerequisites
n Verify that you are connected to a VMware Cloud Director server as a provider administrator.
n Verify that at least one enabled provider vDC is available on the server.
Procedure
1 Create a new organization vDC using the Pay As You Go model for resource allocation.
To create the organization vDC, VMware Cloud Director PowerCLI uses a default configuration
based on the selected resource allocation model.
n CpuGuaranteedPercent is set to 0
2 Modify the vCPU speed setting for the virtual machines in the organization vDC.
3 Enable fast provisioning for the virtual machines in the organization vDC.
Prerequisites
Procedure
u Get all organization vDC networks for the organization named MyOrgVdc.
Prerequisites
Procedure
1 Retrieve the catalog to which you want to add the imported vApp template.
2 Retrieve the organization virtual data center (vDC) to which you want to add the imported
vApp template.
3 Import a virtual machine from your local storage and save it as a vApp template in the cloud.
Prerequisites
Procedure
1 Retrieve the source vApp for the vApp template that you want to create.
3 Retrieve the catalog to which you want to add the new vApp template.
4 Retrieve the organization vDC to which you want to add the new vApp template.
What to do next
Create a vApp from the template and modify the vApp. See Create and Modify a vApp.
Prerequisites
n Verify that you are connected to a VMware Cloud Director server as a provider administrator.
Procedure
2 Retrieve the organization vDC to which you want to import the virtual machine.
Prerequisites
Procedure
1 Retrieve the organization vDC to which you want to add the new vApp.
4 Renew the runtime lease for the new vApp and set it to 12 hours.
Prerequisites
Procedure
1 Power on all virtual machines in all vApps with names starting with MyVApp.
2 Suspend all virtual machines in all vApps with names starting with YourVApp.
4 Shut down the guest operating systems of all virtual machines in the vApp named MyVApp2.
5 Restart the guest operating systems of all virtual machines in the vApp named MyVApp3.
Prerequisites
Procedure
1 Retrieve all virtual machines with names starting with MyVM and power them on.
4 Shut down the guest operating system of the virtual machine named MyVM2.
5 Restart the guest operating system of the virtual machine named MyVM3.
Prerequisites
Procedure
1 Retrieve the organization for which you want to generate the report.
$vAppNetworkAdapters = @()
foreach ($vApp in $vApps) {
$vms = Get-CIVM -VApp $vApp
foreach ($vm in $vms) {
$networkAdapters = Get-CINetworkAdapter -VM $vm
foreach ($networkAdapter in $networkAdapters) {
$vAppNicInfo = New-Object "PSCustomObject"
$vAppNicInfo | Add-Member -MemberType NoteProperty -Name VAppName
-Value $vApp.Name
$vAppNicInfo | Add-Member -MemberType NoteProperty -Name VMName
-Value $vm.Name
$vAppNicInfo | Add-Member -MemberType NoteProperty -Name NIC
-Value ("NIC" + $networkAdapter.Index)
$vAppNicInfo | Add-Member -MemberType NoteProperty -Name
ExternalIP -Value $networkAdapter.ExternalIpAddress
$vAppNicInfo | Add-Member -MemberType NoteProperty -Name
InternalIP -Value $networkAdapter.IpAddress
$vAppNetworkAdapters += $vAppNicInfo
}
}
}
Running this script retrieves the names of the virtual machines and their associated vApp, the
IDs of the NICs of the virtual machines, and external, and internal IP addresses of the NICs.
$vAppNetworkAdapters
Prerequisites
Procedure
2 Modify the access rule for a trusted user who needs full control over MyVApp.
4 Remove the custom rule that you created earlier for MyAdvancedUser.
$accessRule | Remove-CIAccessControlRule
Prerequisites
Procedure
u Get all vApp networks of connection type direct and direct fenced.
u Get all direct vApp networks that connect to the organization vDC network named
MyOrgVdcNetwork.
To address multiple networking scenarios for a vApp, you can create multiple vApp networks.
Prerequisites
Procedure
1 Retrieve the vApp for which you want to create a vApp network.
2 Create the new vApp network with a selected gateway and network mask.
Prerequisites
Procedure
1 Retrieve the vApp for which you want to create a vApp network.
2 Retrieve the organization vDC network to which you want to connect the vApp network.
3 Create the new vApp network with a gateway and network mask, defined pool of static IP
addresses, and a deactivated firewall.
If you do not run New-CIVAppNetwork with the DisableFirewall parameter, the new vApp
network has an active firewall by default.
Prerequisites
Procedure
1 Retrieve the vApp for which you want to create a vApp network.
2 Retrieve the organization vDC network that you want to connect to.
3 Create a direct vApp network that connects to the selected organization vDC network.
Prerequisites
Procedure
1 Retrieve the vApp for which you want to modify vApp networks.
2 Modify the settings for DNS and static IP pool for the vApp network named MyVAppNetwork.
4 (Optional) Remove all isolated vApp networks for the vApp named MyVapp.
The operation deactivates the firewall and NAT routing for all vApp networks that are
connected to MyOrgVdcNetwork1.
The vSphere Update Manager module provides a set of cmdlets for downloading software
patches, creating and modifying baselines, and for scanning and remediating virtual machines
or hosts.
n Stage Patches
n Remediate a Cluster
n Remediate a Host
You can have more than one connection to the same server. For more information, see Managing
Default Server Connections.
If your login credentials contain non-alphanumeric characters, you might need to escape them.
For more information, see Providing Login Credentials.
Prerequisites
n If the certificate of the server you want to connect to is not trusted, verify that your PowerCLI
invalid server certificate action settings are configured properly. For more information, see
Configuring PowerCLI Response to Untrusted Certificates.
n If you use a proxy server for the connection, verify that it is configured properly, so that the
connection is kept alive long enough for tasks to finish.
Note If you do not want to use a proxy server for the connection, run Set-
PowerCLIConfiguration -ProxyPolicy NoProxy.
Procedure
Patch data in dynamic baselines changes depending on the criteria you specify each time Update
Manager downloads new patches. Fixed baselines contain only the patches you have selected,
regardless of new patch downloads.
Prerequisites
Procedure
1 Retrieve all host patches released after 1 Jan 2015 for ESXi products, and create a fixed
baseline named Static Baseline, containing the retrieved patches.
2 Create a critical dynamic baseline named Dynamic Baseline by using a fetch-all query.
Prerequisites
Procedure
1 Attach the host patch baselines stored in the provided variables to the host named Host.
Prerequisites
Procedure
1 Initialize scanning on a virtual machine that is named VM against baselines containing virtual
machine hardware upgrades and VMware Tools upgrades.
The command initializes a task on the server, returns a snapshot object of the initial state of the
task, and saves it in the $task variable.
$task
Note The task object is not updated with the actual state of the task process running on the
server. Even after the task is completed, the $task variable value is running. To view the actual
status of the tasks running on the server, use the Get-Task cmdlet.
3 (Optional) Run the Wait-Task cmdlet to monitor the process progress and wait for the task to
complete before running other commands.
Prerequisites
Procedure
1 Retrieve the compliance statuses with the value Unknown for the baselines attached to the VM
virtual machine and store them in the $statuses variable.
2 Check whether the virtual machine has any baselines with unknown compliance status
attached to it and start a scan.
if ($statuses.Count -gt 0) {
Test-Compliance -Entity VM -RunAsync"
}
Stage Patches
Staging allows you to download patches and extensions from the Update Manager server to the
ESXi hosts without applying the patches and extensions immediately.
Note Staging can be performed only for hosts, clusters, and data centers.
Prerequisites
Procedure
Prerequisites
Procedure
Prerequisites
Procedure
3 Remediate all virtual machines against the virtual machine upgrade baselines.
Remediate a Cluster
You can retrieve all baselines attached to a cluster and remediate the cluster.
Note Before remediation, you must temporarily deactivate the Distributed Power Management
(DPM), High Availability (HA) admission control, and Fault Tolerance (FT) features of the
clusters you want to remediate. After remediation, Update Manager automatically activates the
deactivated features.
Prerequisites
Procedure
Remediate a Host
You can retrieve all baselines attached to a host and remediate the host.
Note When remediating a host, you can configure the maintenance mode settings. You can
temporarily disconnect any removable media devices that might prevent the host from entering
maintenance mode as well.
Prerequisites
Procedure
Prerequisites
Procedure
1 Retrieve all entities from the Datacenter data center and store the result in a variable.
$result = Sync-Patch
3 Check whether new patches are downloaded and start scanning the entities in the Datacenter
data center.
if ($result.Count > 0) {
Test-Compliance -Entity $entities
}
You can have more than one connection to the same server. For more information, see Managing
Default Server Connections.
If your login credentials contain non-alphanumeric characters, you might need to escape them.
For more information, see Providing Login Credentials.
Prerequisites
n If the certificate of the server you want to connect to is not trusted, verify that your PowerCLI
invalid server certificate action settings are configured properly. For more information, see
Configuring PowerCLI Response to Untrusted Certificates.
n If you use a proxy server for the connection, verify that it is configured properly, so that the
connection is kept alive long enough for tasks to finish.
Note If you do not want to use a proxy server for the connection, run Set-
PowerCLIConfiguration -ProxyPolicy NoProxy.
Procedure
Prerequisites
n Verify that you are connected to the vCenter Server system that is monitored by the vRealize
Operations Manager instance.
Procedure
1 Browse the vCenter Server inventory and select a virtual machine host for which you want to
check the memory waste levels.
2 Get the vRealize Operations Manager resource that refers to this virtual machine host.
3 Check the defined metrics for this vRealize Operations Manager resource type.
Note This command retrieves all available metric data with the highest available granularity.
5 Get metric data for the last month aggregated on a daily basis.
Prerequisites
n Verify that you are connected to the vCenter Server system that is monitored by the vRealize
Operations Manager instance.
n Verify that at least one alert is triggered for the virtual machine.
Procedure
2 Get the associated vRealize Operations Manager resource and its associated active alerts.
$myVmAlerts | Get-OMRecommendation
Prerequisites
n Verify that you are connected to the vCenter Server system that is monitored by the vRealize
Operations Manager instance.
Procedure
2 Assign the obtained alerts to the user profile you are currently using.
Prerequisites
n Verify that you are connected to the vCenter Server system that is monitored by the vRealize
Operations Manager instance.
Procedure
1 Get all problematic host resources in vRealize Operations Manager that have red or yellow
health status.
$hosts | Get-VmHost
n Connect to a vCenter Server on VMware Cloud on AWS by Using an OAuth 2.0 Authentication
The VMware Cloud services platform is a web-based application that supports any number of
VMware Cloud services. When you sign up for VMware Cloud services, you access your services
and manage all your users, organizations, and payment methods through this platform. The
VMware Cloud services platform manages common requirements for all cloud services, such as
authentication, user roles, and so on.
When connecting to a VMware Cloud on AWS service, you need to authenticate with the
corresponding VMware Cloud services platform.
Prerequisites
Use the VMware Cloud service web portal to generate an API token for authentication with
PowerCLI.
Procedure
u To connect to a VMware Cloud on AWS server by using the API token, run the following
command.
You can create an OAuth security context by using the New-VcsOAuthSecurityContext cmdlet.
Prerequisites
Use the VMware Cloud service web portal to generate an API token for authentication with
PowerCLI.
Procedure
1 Create an OAuth security context for the VMware Cloud services platform by using an API
token.
Prerequisites
Use the VMware Cloud service web portal to generate an API token for authentication with
PowerCLI.
Procedure
1 Create variables to store the VMware Cloud API token and the VMware Cloud on AWS
GovCloud (US) endpoints.
Prerequisites
Procedure
Get-VmcSddc
Prerequisites
n Configure the VMware Cloud on AWS networking to provide access to the vCenter Server
system running on the cloud.
Procedure
2 To connect to the vCenter Server system, provide the vCenter host name and credentials.
Prerequisites
n Configure the VMware Cloud on AWS networking to provide access to the vCenter Server
system running on the cloud.
Procedure
1 Create an OAuth security context for the VMware Cloud service by using an API token.
Prerequisites
Procedure
$awsAccount = Get-AwsAccount
2 Get the VMware Cloud on AWS Virtual Private Cloud (VPC) subnets.
3 Create an SDDC.
Prerequisites
Procedure
Prerequisites
Procedure
1 Create a variable with the SDDCs of the clusters you want to manage.
Prerequisites
Procedure
1 Create a variable with the SDDCs from which you want to remove clusters.
Add hosts to an SDDC with PowerCLI. You can use the Cluster parameter to indicate in which
cluster you want to add the hosts. If you do not specify a cluster, the hosts are added to the
default cluster of the SDDC.
Prerequisites
Procedure
1 Create a variable with the SDDCs in which you want to add hosts.
Remove hosts from an SDDC with PowerCLI. You can use the Cluster parameter to indicate from
which cluster you want to remove hosts. If you do not specify a cluster, the hosts are removed
from the default cluster of the SDDC.
Prerequisites
Procedure
1 Create a variable with the SDDCs from which you want to remove hosts.
You can use the following options to troubleshoot problems with PowerCLI.
Self-Help
As a first step, use the existing documentation to search for a solution to your problem. You can
search the following resources.
Note PowerCLI is not available for selection as a product in the technical support request form.
You must select the product that you are having issues with, for example, vCenter Server, VMware
ESXi, and so on.
n Clarification of the scope of tasks for which you can use PowerCLI.
Note The SDK and API support engineers do not write or test your code, but they might suggest
sample code for a possible solution.
If you encounter a problem in PowerCLI that you cannot resolve, you can open a support request
for VMware.
Generate and download a PowerCLI support bundle in the form of a ZIP file and attach it to your
VMware support request.
Procedure
$errorcode={
$vm = Get-VM vCLS*
Start-VM $vm
}
2 Generate and download the support bundle by running the Get-ErrorReport cmdlet.
Optional: Тo limit the size of your support bundle, include the MaxDataDepth parameter which
specifies object data depth for the report. For example, to limit object data depth to one level,
add -MaxDataDepth 1 to the above example.
Results
The ZIP file that contains environmental information about the error is saved at the specified
destination.
What to do next
Attach or upload the ZIP file and submit your VMware support request.