One of the key benefits of VMware Cloud on AWS is how the service provides a consistent platform between it and on-premises VMware environments. This also extends out to include the use of PowerCLI for the service’s automation tasks and workflows!
The good news, a majority of the scripts out there today will work just as normal! For those that do not work, there are some simple workarounds. We are going to be walking through some of those workarounds in this blog post to help prepare your scripts to work optimally with VMware Cloud on AWS.
Resource Creation Scripts
VMware Cloud on AWS operates under a limited permissions model, due to it being a managed service. This model will have some impact when resources like VMs, folders, resource pools, and so forth are created. This is because those resources can only be placed beneath the “Workloads” folder and within the “WorkloadRP” resource pool.
The main cmdlets which involve these types of actions are as follows:
We can use the following code to detect if any scripts we have currently used these cmdlets. The code should be run against the main local directory, or repository, where scripts are held.
$array = @(“Import-VApp”, “New-Folder”,”New-ResourcePool”,”New-Template”,”New-VApp”,”New-VM”)
Get-ChildItem -Include *.ps1 -Recurse | Select-String -Pattern $array
Figure 1. A variety of scripts have been returned which show the use of those six cmdlets.
Now that we have identified which scripts need to be examined a little further, we can start verifying whether they will need to be modified. Taking a look at the first response from Figure 1, we can see that this script is creating a new Resource Pool and is using the Location parameter to point to a cluster. If we used this script against a VMware Cloud on AWS environment, it would not work. This can be resolved by specifying the “WorkloadRP” resource pool, or a resource pool located within the “WorkloadRP” resource pool instead.
Updated Code Example:
New-ResourcePool -Location (Get-ResourcePool -Name WorkloadRP) -Name LimitedRP
Taking a look at the second response from Figure 1, we can see there are numerous issues. First issue, the usage of the VMHost parameter will need to be replaced with the ResourcePool parameter which should be pointing to the “WorkloadRP” resource pool. Second issue, a destination folder is not specified. By default, PowerCLI will place the VM in the root of the datacenter folder. However, we do not have permissions to create a VM in that location so we will need to specify a folder. This can be accomplished by making use of the “Location” parameter and specifying a location of either “Workloads” or a folder located beneath the “Workloads” folder.
Updated Code Example:
New-VM -ResourcePool (Get-ResourcePool -Name WorkloadRP) -Location (Get-Folder -Name Workloads) -VMFilePath $vmx
The last script will need to make use of a new parameter available as part of PowerCLI 6.5.2.
InventoryLocation Parameter Usage
PowerCLI 6.5.2 introduced a new parameter for a handful of cmdlets. The new parameter named “InventoryLocation” and accepts folder type objects. This parameter is available on the following cmdlets:
The third response from Figure 1 is creating a new vApp. In this case the “Location” parameter is already in use and specifying a cluster. This parameter’s input will need to be modified to specify the “WorkloadRP” resource pool. Then, we can make use of the new InventoryLocation parameter to specify the folder location of where this new vApp should reside.
Updated Code Example:
New-VApp -Name $vapp -Location (Get-ResourcePool -Name WorkloadRP) -InventoryLocation (Get-Folder -Name Workloads) -Confirm:$false
Summary
VMware PowerCLI remains as one of the ‘go-to’ management and automation options when working with on-premises VMware environments as well as when using VMware Cloud on AWS. While most scripts, modules, and other resources will work out of the box there are a couple workarounds available for those that do not. A simple script, available above, can help identify some of the scripts which will need to be updated. Once discovered, it is quite easy to remedy any issues which may arise by updating those scripts to instead use the “WorkloadRP” resource pool and/or the “Workloads” VM folder.