Category Archives: PowerCLI

Automating VMware Cloud Foundation with PowerVCF

In a recent post, I wrote about interacting with VCF using the API to add a new license key as a simple way to begin familiarizing myself with the API. As a huge proponent of PowerShell, I began looking for a module to talk to the API but came up empty handed. I began working on a module with vSphere admins in mind because I know the important role PowerShell plays in day-to-day operations. During a conversation with Jase McCarty, he told me about the PowerVCF project which does exactly that! The module was initially developed and is maintained by Brian O’Connell and has 50 cmdlets which covers ~70% of the API calls in VCF 3.9.0:

  • Get/Commission/Decommission Host
  • Get/New/Set/Remove Workload Domain
  • Get/New/Set/Remove vSphere Cluster
  • Get/New/Remove Network Pool
  • Get/New/Remove Network IP Pool
  • Get/New/Remove License Keys
  • Get/Retry Tasks
  • Get/Set Credentials
  • Get/Set participation in CEIP
  • Get/Start Backup Configuration
  • Get/Request Log Bundle
  • Get/Set Microsoft Certificate Authority
  • Get/Request Certificate CSRs
  • Get/Request/Set Certificates
  • Get/Set Depot Credentials
  • Get PSCs & vCenter servers managed by SDDC Manager
  • Get NSX-V Managers
  • Get NSX-V/T Clusters
  • Get vRealize Log Insight info
  • Get vRealize Lifecycle Manager & Environment info
  • Get vROPS info

PowerVCF is also mostly compatible with VxRAIL too with the exception of commissioning and decommissioning hosts, working with network pools, and creating and removing workload domains.

The biggest functionality missing right now are creating and deleting PKS/Horizon workload domains and creating/joining/tearing down federations. I’m currently working on the PKS workload domain functions and plan to submit a PR soon!

If you’ve recently deployed VCF and looking to orchestrate functionality, I highly recommend checking this module out! If you enjoy creating PowerShell cmdlets and looking to contribute to a project, you’ll find quite a few opportunities to help us work towards feature parity!

Enable Software iSCSI Adapter Using PowerCLI

I recently began studying for the VCAP5-DCA (VDCA550) and in the course of administering a 2 host environment, it’s very rare that I have to use PowerCLI. The time it would take to write the script would easily exceed the time to perform the task by hand. But section 7 of the VCAP5-DCA blueprint states that the exam will cover PowerCLI and vCenter Orchestrator (vCO) so as I go work through the blueprint, I intend on becoming very comfortable with many different tasks in PowerCLI.

From what I’ve read about the VCAP5-DCA (VDCA 550 version), the exam environment now contains 5 hosts. Performing the same task on this many hosts in a limited amount of time is a good opportunity to automate as much as possible. I don’t think creating a powershell script for each minute task is a good use of time but over the course of learning PowerCLI, I will post many PowerCLI scripts that coincide with VCAP5-DCA blueprint objectives.

We’ll begin with enabling the software iSCSI initiator on all hosts in the datacenter. If the environment is already setup with NFS storage, there’s a good chance that the the software iSCSI initiator will need to be added to the hosts to connect to iSCSI storage. The script uses a hardcoded username and password since this is a test environment but I wouldn’t recommend doing that in production. To use in your environment, use your username, password, and name of each host. Make sure the name of your hosts matches what’s in vCenter. If it’s in vCenter with a FQDN, mirror the name in the script. Next, open PowerCLI and run the script with .\iSCSI.ps1.


$vcenter “name”

$username “username”

$password “password”

$listofhosts = “host1”, “host2”, “host3”

#connect to vcenter

write-host “Connecting to vcenter”

connect-viserver $vcenter -user $username -password $password

#Loop through hosts

foreach ($esxhost in $listofhosts)


$currentesxhost = get-vmhost $esxhost

write-host “Enabling software iSCSI initiator on $currentesxhost”

get-vmhoststorage $currentesxhost | set-vmhoststorage -softwareiscsienabled $true


write-host “Disconnecting from vcenter”

disconnect-viserver $vcenter