VMware Cloud Community
larstr
Champion
Champion
Jump to solution

New-VM and Folder location

Hi,

I'm trying to create a new VM and put it in the correct folder. I'm having a problem since we have multiple data centers defined and as our applications are distributed in several data centers like this:

PowerCLI C:\ps> Get-Folder -Name System32

Name                           Type

----                           ----

System32                          VM

System32                          VM

In the Blue Folder(tm) structure we see this as a single folder with VMs from all data centers.

Now when I try to create a VM within this Folder I will get an error message:

New-VM -VMFilePath @{Name=larstest; ResourcePool=Resources; Folder=System32; VMXPath=[LT_NFS05] larstest/larstest.vmx}.VMXPath -VMHost LTesxp11.acme.org -Location @{Name=larstest; ResourcePool=Resources; Folder=System32; VMXPath=[LT_NFS05] larstest/larstest.vmx}.Folder -ResourcePool (Get-Cluster LTCLP | Get-ResourcePool @{Name=larstest; ResourcePool=Resources; Folder=System32; VMXPath=[LT_NFS05] larstest/larstest.vmx}.ResourcePool)PowerCLI

New-VM : 20.01.2015 10:26:40    New-VM        The specified parameter 'Location

' expects a single value, but your name criteria 'vm' corresponds to multiple v

alues.

At C:\ps\restorevms.ps1:7 char:9

+   New-VM <<<<  -VMFilePath $vm.VMXPath -VMHost $ESXHost -Location $vm.Folder

-ResourcePool (Get-Cluster $cluster | Get-ResourcePool $vm.ResourcePool)

    + CategoryInfo          : InvalidResult: (System.Collecti...dObjectInterop

   ]:List`1) [New-VM], VimException

    + FullyQualifiedErrorId : Core_ObnSelector_SelectObjectByNameCore_MoreResu

   ltsThanExpected,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

Name                 PowerState Num CPUs MemoryGB

----                 ---------- -------- --------

larstest             PoweredOff 1        4,000

The VM is created, but located in the root of the Blue Folders(tm). How can I single out the folder location?

Lars

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Hi Lars,

You might want to have a look at my  Folder by Path post.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Hi Lars,

You might want to have a look at my  Folder by Path post.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
larstr
Champion
Champion
Jump to solution

Thanks LucD,

Your posting is spot on!

Lars

0 Kudos