Close Menu
DPC Virtual Tips
    Read More

    How to Investigate TCP Retransmissions on Linux

    August 11, 2026

    Slurm Node Is DRAINED: How to Find the Exact Reason

    August 10, 2026

    Why Is My Slurm Job Pending? How to Decode Every Common Reason

    August 9, 2026
    • Home
    • About Us
    • Contact
    • Cookie Policy
    • Comment Policy
    • Privacy Policy
    • Terms of Use
    • Disclaimer
    Tuesday, August 11
    DPC Virtual Tips
    • Home
    • Operating Systems
    • PowerFlex
    • HPC
    • Virtualization
    • About the Author
    • About Us
    • Contact
    DPC Virtual Tips
    Home » Introduction to the VMware PowerCLI
    Virtualization

    Introduction to the VMware PowerCLI

    DaniloBy DaniloNovember 13, 2022Updated:August 5, 2026No Comments7 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    VMware PowerCLI
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Introduction to the VMware PowerCLI is an article that introduces the very interesting commands that helps to administrate a vSphere Environment from Powershell CLI. Besides, it’s a very useful thing to automate a lot of administrative tasks 😉

    VMware PowerCLI is a command-line and scripting tool built on Windows PowerShell and provides more than 800 cmdlets for managing and automating VMware vSphere, VMware Cloud Director, vRealize Operations Manager, vSAN, VMware NSX-T Data Center, VMware Cloud Services, VMware Cloud on AWS, VMware HCX, VMware Site Recovery Manager, and VMware Horizon environments.

    To access the VMware PowerCLI user’s guide, the below link can be used:

    • https://developer.vmware.com/docs/15315/powercli-user-s-guide

    Install and Configure VMware PowerCLI

    So, open a Windows Powershell with administrator rights and install the PowerCLI module:

    Install-Module -Name VMware.PowerCLI

    Note: An alert will show about the Untrusted repository “PSGallery”. Type “A” and then press ENTER. If you don’t have the admin rights for some reason, you can install it with the command below:

    Install-Module VMware.PowerCLI -Scope CurrentUser

    If necessary, update VMware.PowerCLI module:

    Update-Module VMware.PowerCLI

    When you try to connect to a server, PowerCLI checks whether the server certificate is valid.
    You might have to configure the PowerCLI settings to be able to connect to servers with untrusted certificates. So, in this example, we will configure PowerCLI to show a prompt:

    Set-PowerCLIConfiguration -InvalidCertificateAction Prompt

    Another thing is to disable CEIP:

    Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false

    Connect to the vCenter Server

    The FQDN of our vCenter Server in this lab is “vcsa01.lab.local”. So, the PowerCLI string to connect to the vCenter Server is:

    Connect-VIServer -Server vcsa01.lab.local

    Note: A prompt with an Invalid server certificate warning is showing. Nevertheless, type “P” to accept permanently this certificate. In this context, this certificate is invalid due the client machine doesn’t trust the CA (Certificate Authority) that expedites the vCenter Server certificate.

    In the meantime, a Window prompt will be shown. So, type the username and password. In this case, for instance, we are using the “administrator@vsphere.local” to connect to the vCenter Server:

    If the connection is established, a message like below will be shown. However, if you don’t receive a message like it, check if the user credentials are correct:

    Search for a command, for example, that has “snapshot” on a command:

    Get-Command -Name *snapshot*

    To get help with a particular command, for example:

    Get-Help Get-Snapshot

    Note: In some cases, for example, it is necessary to run the “update-help” to update the help content. Type “Y” to update the help content for the command “Get-Snapshot”.

    Manage Virtual Machines on vSphere

    So, to view all Virtual machines:

    Get-VM

    Start the VM virtual machine:

    Get-VM VM_NAME | Start-VM

    Note: Change “VM_NAME” to the correct Virtual Machine name.

    Get information on the guest OS of the VM virtual machine:

    Get-VMGuest VM | fc

    Shut down the OS of the VM virtual machine:

    Stop-VMGuest VM_NAME

    Power off the VM virtual machine:

    Stop-VM VM_NAME

    Move/migrate the virtual machine VM from the Host01 host to the Host02 host:

    Get-VM -Name VM_NAME -Location Host01 | Move-VM –Destination Host02


    Manage Datacenter, Cluster, and ESXi hosts on vSphere

    Get all data centers present on the vCenter Server:

    Get-Datacenter

    Cluster:

    Get-Cluster

    Get all ESXi hosts managed by the vCenter Server:

    Get-VMHost

    Put an ESXi host into maintenance mode – However, use this command if DRS is enabled and the fully automated method is used. In this example, the host FQDN is “host01.lab.local”:

    Set-VMHost -VMHost host01.lab.local -State "Maintenance"

    Remove and ESXi host from maintenance mode – use this command if DRS is enabled and the fully automated method is used:

    Set-VMHost -VMHost host01.lab.local -State "Connected"

    If DRS is enabled but not automated or partially automated, it needs first generate a DRS recommendation and wait until all powered-on virtual machines are relocated to other hosts:

    Set-VMHost -VMHost host01.lab.local -State "Maintenance" -RunAsync

    Get and apply the recommendations generated by DRS:

    Get-DrsRecommendation -Cluster "CL-LAB.LOCAL" | where {$_.Reason -eq "Host is entering maintenance mode"} | Invoke-DrsRecommendation

    Remove the ESXi host from maintenance mode:

    Set-VMHost -VMHost host01.lab.local -State "Connected"

    Get all Datastores available on the vCenter Server:

    Get-Datastore

    Create a VM based on a Template

    Firstly, it is necessary to get all VM templates available on the vCenter Server:

    Get-Template

    Secondly, we need to understand the basic syntax to create a VM . So, the basic syntax for it is:

    New-VM –Name VM_NAME –ResourcePool CLUSTER_NAME –Template TEMPLATE_NAME -Datastore DATASTORE_NAME

    In detail:
    — VM_NAME = Virtual Machine name
    — CLUSTER_NAME = Cluster name or ESXi host name to host the new Virtual Machine
    — TEMPLATE_NAME = Template name that will be used to create the Virtual Machine
    — DATASTORE_NAME = Datastore name that will be used to store the Virtual Machine

    In our lab, for instance, the syntax to create the VM is:

    New-VM -Name "vm-01" -ResourcePool host01.lab.local -Template Template-FreeBSD-13 -Datastore ISCSI02

    After a few seconds, the Virtual Machine is created:

    On the vSphere Client interface, it’s possible to confirm the task used to create this Virtual Machine:

    On the VMs tab, we can see the new Virtual Machine “vm-01′:

    Remove a VM from the vCenter Inventory

    To remove a Virtual Machine from the vCenter inventory:

    Remove-VM -VM VM_NAME

    Note: In some cases, it’s necessary to remove a Virtual Machine, especially from Disk, the syntax of the command is:

    Remove-VM -VM VM_NAME -DeletePermanently

    Create multiple Virtual Machines from a Template

    In some cases, especially for lab environments, it’s necessary to create a lot of Virtual Machines for tests or something like that. There is a way to create multiple Virtual Machines using a script. Below, we will give more details about it.

    We will use a lot of variables to set the values that we want to use in our script. This is the most important step and, pay attention to it:

    — Define the Cluster Name or the Hostname that the Virtual Machines will use:
    Get-Cluster –> and copy the cluster name if you want to use the cluster
    Get-VMHost –> and copy the hostname if you want to use the host or if the DRS service is disabled on your environment

    In this case, for example, we are using the ESXi host02.lab.local. The variable for it is:

    $host2 = Get-VMHost host02.lab.local


    — Define the Template Name that the Virtual Machine will use:
    Get-Template –> and copy the template name

    In this example, we are using the template name “Template-FreeBSD-13”. The variable for it is:

    $template = Get-Template Template-FreeBSD-13


    — Define the Datastore Name that the Virtual Machine will use:
    Get-Datastore –> and copy the datastore name

    In this example, we are using the datastore name “ISCSI02”. The variable for it is:

    $datastore = Get-Datastore ISCSI02

    We will create 10 Virtual Machines using the script below:

    $vmNameTemplate = “VM-{0:D3}”

    $vmList = @()
    for ($i = 1; $i –le 10; $i++) {
    $vmName = $vmNameTemplate –f $i
    $vmList += New-VM –Name $vmName –ResourcePool $host2 -Template $template -Datastore $datastore
    }

    Note: So, each Virtual Machine will be created with the name “VM-0XX”. In this example, the Virtual Machines’ name there is:

    VM-001
    VM-002
    …
    …
    VM-010

    After running the loop script, each Virtual Machine will be created in a serial way:

    In parallel, it’s possible to follow the tasks on the vSphere Client:

    In this case, for example, the loop script ended with an error because the datastore is full 🙂

    However, 9 Virtual Machines have been created by the loop script:

    To disconnect to the vCenter Server, you can use the below command:

    Disconnect-VIServer
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleHow to install FreeBSD 13
    Next Article How to Install CentOS 7
    Danilo

    Infrastructure Engineer with experience in Virtualization, Linux, Windows Server and learning automation using Python. DPC Virtual Tips was created to share practical tutorials, lab experiences and troubleshooting guides focused on enterprise infrastructure technologies.

    Related Posts

    VM Replication with vSphere Replication and Site Recovery Manager

    June 16, 2025

    Changing DNS Settings on ESXi Hosts

    May 20, 2025

    Changing NTP Settings on ESXi Hosts

    May 19, 2025

    Comments are closed.

    Search
    Categories
    • HPC (10)
    • Operating Systems (83)
    • PowerFlex (22)
    • Virtualization (129)
    Read More
    Operating Systems

    How to Investigate TCP Retransmissions on Linux

    By DaniloAugust 11, 20260
    HPC

    Slurm Node Is DRAINED: How to Find the Exact Reason

    By DaniloAugust 10, 20260
    HPC

    Why Is My Slurm Job Pending? How to Decode Every Common Reason

    By DaniloAugust 9, 20260
    Operating Systems

    Linux Process Resource Usage: How to Find Heavy Processes

    By DaniloAugust 6, 20260
    HPC

    Lustre Filesystem Commands: A Practical Admin Guide

    By DaniloAugust 5, 20260
    Latest Posts

    How to Investigate TCP Retransmissions on Linux

    August 11, 2026

    Slurm Node Is DRAINED: How to Find the Exact Reason

    August 10, 2026

    Why Is My Slurm Job Pending? How to Decode Every Common Reason

    August 9, 2026
    Images from Gallery
    hpc main commands
    linux commands
    install rock linux
    lustre fs
    shell scripting
    vSAN Trace Files
    Categories
    • HPC
    • Operating Systems
    • PowerFlex
    • Virtualization
    • Home
    • About Us
    • Contact
    • Cookie Policy
    • Comment Policy
    • Privacy Policy
    • Terms of Use
    • Disclaimer
    Copyright © 2026, DPC Virtual Tips. All rights reserved.

    Type above and press Enter to search. Press Esc to cancel.

    We use cookies to ensure your best experience on our website. If you continue using our website, we'll assume you agree to our cookie policy