Your PowerCLI Questions Answered

Save to My DOJO

Your PowerCLI Questions Answered

Working with VMware PowerCLI is one of those things many IT professionals leave aside as they don’t know where to start and what problems it can solve for their organization. Although there is a learning curve, it is not as steep as one might think. Being built on PowerShell, the syntax makes it a great language to start on your scripting journey. In this article, we answer your questions about VMware PowerCLI to help you automate your vSphere tasks efficiently.

The questions gathered below were generated from a webinar in which I teamed up with the author of “PowerCLI: The Aspiring Automator’s Guide”, Xavier Avrillier, to provide an introduction to VMware PowerCLI and demonstrate use cases on how it can help at different levels.

    • Installing PowerCLI on a Non-Windows Operating System
    • Testing PowerCLI Code with vCenter and Docker
    • HTML Reporting with PowerCLI
    • 3rd Party Rest APIs and PowerCLI
    • Building PowerCLI Tools

If you didn’t attend the session, you can watch the recording of that webinar right now. 

powercli superhero webinar

You can also download the resources demonstrated during the webinar on our Github repo.

PowerCLI Questions Answered

Q. Is it good practice to always install the latest version of PowerShell or remain a few point versions behind?

A. It is best practice to at least run the major version of PowerShell (5.1) which is mainly tied to your Windows version anyway. However, using the latest version of VMware PowerCLI is best as cmdlets are added and others are deprecated across versions.

Q. We are running VMWARE 5.5. currently. Could we use PowerCLI with it?

A. Absolutely. Although vSphere 5.5 is no longer supported and an upgrade is highly recommended, you can still connect to it via PowerCLI up until version 10.2.0. Refer to VMware’s interoperability matrix and unselect “Hide Legacy Releases”.

Q. What free tools such as Chef/Puppet leveraging PowerCLI can further enhance its automation potential and span to large scale use cases? (hundreds of VM deployments, re-ip, snapshotting) …

A. PowerCLI is a way to connect to an endpoint and manage it through a set of cmdlets leveraging its API. Automation tools such as Chef and Puppet will do the same thing through a different interface and language. The value is that you don’t need PowerCLI at all unless for very specific use cases where you have to trigger a script from a PowerShell source.

You may want to check out vRealize Orchestrator which is included in the vCenter license.

Q. How can I use PowerCLI to determine what users are connected via VMRC?

A. There is currently no reliable way to determine VMRC sessions currently in use. You can query the events of each VM and look for the string “A ticket for * of type webmks on * has been acquired”. This will tell you when a VMRC was open and by whom, however, you won’t know if the console is still open as there is no event logged when the user closes it.

You can get started with the following piece of code which will look for this event in the past 30 minutes with 300 samples per VM for execution’s speed’s sake. Meaning if the VMRC open event is the 301st event, it won’t show up.

Get-VM | ForEach-Object {$_ | Get-VIEvent -Start (get-date).AddMinutes(-30) -MaxSamples 300 | where Fullformattedmessage -like “A ticket for * of type webmks on * has been acquired”} | select createdtime,username,@{l=”VM”;e={$}}

Q. So PowerCLI is PowerShell for the VMware hypervisor?

A. PowerCLI is a collection of PowerShell modules provided by VMware. They allow you to connect to VMware endpoints and offer cmdlets to interact with them. Note that PowerCLI isn’t limited to vSphere (Hypervisor). You can use it to connect to various types of endpoints such as SRM, Horizon, VMC on AWS, NSX…

Q. Is root really needed to run pwsh on Linux?

A. No, pwsh will run fine as a regular user.

Q. How can I find the path of an OVF Template which I could use in Ansible?

A. When exporting to an OVF template, it is downloaded in your computer’s Downloads folder by default.

Q. Can we use the deployment script (GUI – demonstrated during the webinar) to integrate with CI/CD Tools like Jenkin or Builtkite?

A. No. The deployment script that was demonstrated is only a wrapper, in the form of a GUI, for a collection of commands that will safely deploy a VM.

Altaro product related questions

Q. Can a Banking customer rest assured that doing backup only on the DR remote site thru Altaro is good for banking regulatory compliance?

A. A disclaimer first prior to answering this question. I am NOT a compliance expert, and any answer taken here should be directed at your company’s compliance officer or legal consul for further verification.

That said, if I’m understanding the question correctly, it sounds like you intend to only run backups at the remote end of the replication target? If that’s the case I would recommend against that. Best practice for any organization would include running local backups at the production site as well. Not only will these “onsite” backups provide you with your day to day restoration capabilities without having to pull files across a WAN, they are often the most time-efficient and current of backups as well.

In short, I think running backups against the replicated data at the remote site is fine and probably a good idea for an organization with sensitive compliance requirements, but I would also take the step of running local backups at the production location as well.

Altaro VM Backup
Share this post

Not a DOJO Member yet?

Join thousands of other IT pros and receive a weekly roundup email with the latest content & updates!

Leave a comment

Your email address will not be published. Required fields are marked *