Creating VMs and Templates folders with PowerCLI

As part of a migration from one vCenter to another, I wanted to recreate the same VMs and Templates look which meant recreating the folders. This is VERY slow in the vSphere Web Client and only slightly less tedious in the C# client, so I thought I’d use PowerCLI to do the trick. Here is the folder structure I wished to recreate:

-Pending DeComm
  -Active Directory Domain Controllers
  -Linux Servers
  -RDP Servers
  -Template VMs

PowerCLI has a cmdlet called New-Folder. Unfortunately, it only creates folders of the Hosts and Clusters type. To create a new VMs and Templates folder, we have to use the Get-View cmdlet. By viewing a datacenter or folder and filtering on the proper location, we can call methods to create a folder with the right context:

Continue reading