How to manage ESXi hosts remotely with PowerCLI

PowerCLI is a PowerShell-based framework that allows administrators to create scripts that process repetitive processes. Learn how to use PowerCLI to manage VMware ESXi hosts remotely.

Image: yucelyilmaz, Getty Images / iStockphoto

When they choose to manage VMware-based virtual machines (VMs), administrators must make a number of decisions when preparing their bare-metal hosts and configuring the guest operating systems, storage areas and switches used to communicate with each other and over networks to communicate. The choices are focused on configuring the hosts and VMs once the first specifications have been chosen.

SEE: How to become a network administrator: a cheat sheet (free PDF) (TechRepublic)

Some administrators choose to install ESXi manually via removable media; others prefer to use the kickstart scripting method to initially configure hosts during the installation process. Both approaches require a form of presence on site – a technician to start the server manually and a form of bootstrap to perform the installation. Administrators can also use vCenter to centrally manage VMs using host profiles. While this solution may be the best, not all organizations have a vCenter license, which may be expensive.

But luckily for us there is another option called PowerCLI, which acts as a PowerShell (PS) module and is supported on Windows, macOS and Linux. PowerCLI is flexible enough to run after installation and allows IT to create scripts that can be used to perform management tasks. Like all scripts, they can be saved for future use, regardless of how the server was initially set up.

Because each ESXi server is configured differently depending on the needs of the organization, this article does not discuss the details of the commands that must be performed to perform specific administrative tasks. The purpose of this article is to help administrators install PowerCLI on their management stations, as well as how to navigate through the console and find resources used to manage their hosts and VMs.

Requirements:

How to install PowerCLI

1. Start PowerShell. If you use Windows, use Run as an administrator.
2. Run the following command:
Installation module VMware.PowerCLI
3. Allow the installation to continue if prompted.
Once completed, all required cmdlets and their dependencies are ready for use.

Use PowerCLI

Because PowerCLI is based on the PowerShell framework, administrators with PS experience will be familiar with the cmdlets and syntax. For those who have little or no experience with using PS, here are commonly used cmdlets (commands in PowerShell) to better understand how they can find commands, what they do and how they can be used to perform management tasks for automation.

PowerShell’s implementation policy

PowerShell contains an execution policy that limits current running scripts; this is to prevent users from inadvertently running a script that could irreversibly cause a system problem. But if you want to allow this, you can execute scripts without restriction using the cmdlet below.
Set-ExecutionPolicy unlimited

List of available cmdlets in PowerShell

Run the cmdlet below to get a complete list of all available cmdlets for PS – including the PowerCLI commands.
Get Command

Get the Help index from PowerShell

PowerShell contains a built-in Help index that provides insight into the cmdlets, including the syntax and examples.
Get-Help Connect-VIServer examples
With a few basic principles about getting help from PowerShell, let’s review a few cmdlets used to configure hosts.
Connect to ESXi hosts
Connect-VIServer -Server IP_ADDRESS -Protocol https -User US password
Obtain system information
Get-VMHost | Format List
Get a list of VMs and status
Get-VM | Format List
Get detailed information about a specific VM
Get-VMGuest GUEST_NAME | Format List
View Datastore information
Get-HardDisk -Datastore DATASTORE_NAME
Start a specified VM
Start-VM-VM VM_NAME – Confirm
Restart the operating system of a specified VM
Restart-VMGuest -Guest GUEST_NAME -Confirm
Restart a specified host server
Restart-VMHost -VMHost HOSTNAME -Force

This is certainly not an extensive list, but it should encourage administrators to manage their ESXi infrastructure remotely. Combine this knowledge with research into VMware community forums and other resources, such as GitHub, for script guidance and, of course, hands-on learning to work out scripts that best meet the needs of the organization.

Datacenter Trends Newsletter

DevOps, virtualization, the hybrid cloud, storage and operational efficiency are just a few of the topics of the data center that we will emphasize.
Delivered on Monday and Wednesday

Register today

Also see

Similar Posts

Leave a Reply