General

Getting (re)Started with PowerActions

The vSphere HTML5 Web Client Fling version 5 has been released and there is a much-awaited surprise: PowerActions is back!

PowerActions is the easiest way to run PowerCLI commands and scripts directly from the vSphere Client. Its first appearance was at VMworld in 2013! It was then introduced in 2014 with a PowerCLI Console and the ability to access a PowerCLI Script Library directly through the vSphere Web Client. However, since that time, the vCenter Server has changed dramatically. The Windows vCenter has evolved into a vCenter Server Appliance (VCSA). The vSphere Web Client has been deprecated and been replaced with the HTML5 based vSphere Client.

To help aid us in the process of these transitions was the introduction of a fantastic utility known as the vSphere HTML5 Web Client Fling. This fling allowed us to introduce the latest and greatest functionalities outside of the normal vSphere release cycle. A little more than a year ago, the fling introduced the concept of a Developer Center. This centrally located area has been the target for all kinds of resources that developers and automation specialists look for. To date, there has been the introduction of Code Capture and the API Explorer. This latest update to the fling re-introduces PowerActions.

In the spirit of the original, this version of PowerActions comes with two distinct areas within the Developer Center: PowerActions and Console. The PowerActions section gives access to two subsections, Script Library and Script Execution. These will be the areas where scripts can be imported, ran, and their output can be viewed. There’s also the Console section, which is a minimal PowerShell console, with access to the PowerCLI 11.5 modules, where commands and scripts can be input and ran ad hoc.

Let’s take a more in-depth look at getting started with PowerActions for the vSphere Client.

Introducing the Script Execution Service

There is a new service behind the scenes that gives PowerActions the ability to run PowerCLI scripts and commands directly from the vSphere Client. This service is known as the Script Execution Service (SES). Under the covers, SES is managing a runspace containing PowerShell 6.1 and the collection of modules for PowerCLI 11.5. This runspace is single threaded, stateless, and periodically refreshed. Therefore, we can only run one script at a time and we should not be storing anything to the local filesystem of the runspace. Control of this service can be found in the Fling Appliance Management Interface (FAMI), and is disabled by default.

Setting Up PowerActions

The first step in using PowerActions is to enable SES from the FAMI. This interface is available at port 5490 of your recently deployed or updated vSphere HTML5 Web Client Fling appliance.

Example: Enabling SES

PowerActions makes use of a Content Library to store and reference scripts. We can either create a new Content Library or use an existing one. If you do find yourself having to create a Content Library, ensure that your permissions are configured at the “Global Permissions” level.

In this environment, I’ll need to create a new Content Library. As of PowerCLI 11.5, we can create a Content Library with a single command. Taking some code from the last blog post, What’s New for Content Library Management, we can use the following code to create a new Content Library.

We can now return to the PowerActions tab and start by importing our first script. The next couple sections are going to start with a high-level report then we’ll add some contextual intelligence to take advantage of PowerActions’ more advanced functionalities.

Snapshot Management – Simple Script

Managing snapshots across an entire environment frequently comes up as a pain point. With PowerActions, we can create and import a one-liner script to audit our entire vSphere environment that can be ran by anyone with access to our vSphere Client.

Here’s the body of the one-liner script we’ll be importing, which I’ve named: SnapshotReport_All.ps1

To start, while we’re in the PowerActions tab and Script Library subsection, make sure the desired Content Library has been chosen from the dropdown box on the right-hand side.

Example: Choosing our Content Library

Then, we can begin our import process by clicking “Import”. On the Import Library Item screen, set the Source file to “Local file” and browse to our SnapshotReport_All.ps1 file. The Item name will automatically be populated and we can add notes as needed. Clicking “Import” will complete the process.

The Script Library will now display information about our import script. We will see our name, the Script Type, the version, and the last modified date. Expanding the item will show us even more information, such as the size and the last sync date. Selecting the script will show us the content of the script.

Here’s an example of how the Script Library should display information about the imported Script:
Example: Viewing our imported script

We are now ready to run our script. We can do this directly from the Script Library by clicking the “Run” dropdown and selecting Run.

Once the script has completed running, we’ll see a pop-up containing some basic status information. This pop-up also contains a link back to PowerActions. By browsing to the Script Execution area, we can see the results of whether or not our environment has any snapshots.

Here’s an example of what this process looked like in my environment:
Example: Viewing the output after executing a script

Snapshot Management – Contextually Based

We are now going to take our script a step further by adding some contextual awareness. This gives PowerActions the ability to run the script against specific objects in our vSphere environment. This is done by adding PowerShell parameter blocks to our script.

For our scenario, we only want to return snapshot information from VMs in a specific cluster. Our parameter block will be looking for a strongly typed cluster object.

Here’s what an example script would look like, which will be named: SnapshotReport_Cluster.ps1

Once the above script has been imported, we can run the script against the desired cluster. We will start by changing over to the “Hosts and Clusters” view. We’re going to select a cluster, bring up the “Actions” menu and select “Execute Script”

Example: Executing a script against an object

We’ll then select one of our imported scripts to run. For this scenario, we will select SnapshotReport_Cluster. Note: if you run SnapshotReport_All, you will receive the same results as before since there were no parameter blocks specified.

Example: Choosing our script

Clicking “Ok” will bring us to a Script Parameter screen. We can see that we have our cluster parameter and the input has been configured to be our Management Cluster. Clicking “Ok” again will run our script against the Management Cluster.

Example: Verifying parameters

After a few moments we should see the results pop-up which will take us back to PowerActions. After selecting the Script Executions subsection, we can see the output from our script which has been reduced by two VMs.

Example: Viewing the output after executing a script

Summary

PowerActions is back and available as a new feature within the vSphere Client Developer Center. PowerActions allows us to import scripts to our vSphere environment and execute them with a couple of clicks. This is all thanks to the Script Execution Service, which has been added to version 5 of the vSphere HTML5 Web Client Fling. This blog took a look at setting up PowerActions, creating a Content Library, and importing some scripts to create basic reports. We also added the ability to use one of our scripts in a contextually aware manner, so that PowerActions understands we’re passing in a parameter directly from the user interface!

Let us know how you’re planning to use PowerActions in your environment!

More information about the vSphere HTML5 Web Client Fling can be found here: VMware Flings: vSphere HTML5 Web Client
More information about PowerActions can also be found in the PowerActions_documentation_Fling.pdf, which is available in the dropdown box from the vSphere HTML5 Web Client Fling’s download section.