This is what I have used with the following folder structures as an example:
-Datacenter
-Production
-Servers
-Management
-Servers
New-VM -Template "TemplateName" -name "VMName" -Location (Get-Folder servers | where {$_.Parent -like "Production"}) -VMHost "VMHost" -RunAsync
If you have two similar folder structures with several levels of identical folders you can use run the "Get-Folder | FL" and find the folder you need to identify. You should get an output similar to this:
ParentId : Folder-group-v000
Parent : ParentFolder
IsChildTypeVm : True
IsChildTypeComputeResource : False
IsChildTypeDatacenter : False
IsChildTypeDatastore : False
Type : VM
Name : ChildFolder
CustomFields : {}
ExtensionData : VMware.Vim.Folder
Id : Folder-group-v001
Uid : /VIServer=Domain\DomainUser@FQDN:443/Folder=Folder-group-v001/
Client : VMware.VimAutomation.ViCore.Impl.V1.VimClient
By utilizing the information in the ID field, you can call out that specific folder with the following command:
New-VM -Template "TemplateName" -name "VMName" -Location (Get-Folder | where {$_.ID -like "Folder-Group-v001"}) -VMHost "VMHost" -RunAsync
Hopefully this helps someone!!