VMware Cloud Community
mdwasim
Contributor
Contributor
Jump to solution

New-Folder Confusion

Friends,

A bit confused with new-folder cmdlet.

When I use it for example New-Folder -Location Data-Center -Name Templates

This creates a folder in Hosts and Clusters section, under my Data-Center

Actually, My purpose was to create the folder in VM's and Templates section

Ok, I created a folder ESX01 in VM's and Templates Section manually.

Now I want to move VM's on Host ESX01 to the respective folder.

I used Get-VMHost ESX01 | Get-VM | Move-VM -destination 'ESX01'

This cmd-line moved the VM's to the folder I created Manually.

Here I was expecting an error coz there is no folder named as ESX01 in Hosts and Clusters Section.

Now you might say that we cannot create a folder in Hosts and Clusters under ESX Hosts (ESX server that we have) and move VM's and thats the reason why the Move-VM moved VM's to folder under VM's and Templates.

OK, I agree, but how to create a folder under VM's and Templates via powerCLi.?

Thanks for your time..

Wasim.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You have to use the hidden folder 'vm' for that

Like this

New-Folder -Name 'MyFolder' -Location (Get-Folder -Name 'vm')

If you have more than 1 datacenter in your vCenter, you will have to specify which 'vm' folder.

Like this for example

New-Folder -Name 'MyFolder' -Location (Get-Folder -Name 'vm' -Location (Get-Datacenter -Name 'MyDC'))

____________

Blog: LucD notes

Twitter: lucd22


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

You have to use the hidden folder 'vm' for that

Like this

New-Folder -Name 'MyFolder' -Location (Get-Folder -Name 'vm')

If you have more than 1 datacenter in your vCenter, you will have to specify which 'vm' folder.

Like this for example

New-Folder -Name 'MyFolder' -Location (Get-Folder -Name 'vm' -Location (Get-Datacenter -Name 'MyDC'))

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
mdwasim
Contributor
Contributor
Jump to solution

Thanks LucD, thats really helpful.

I did create folder using hidden folder i.e., VM. and also noticed the difference in ID when folders are created. the number is prefixed with " v " and " h " for folders created in VM's & Templates and Hosts and Clusters respectively.

You know what i did? I created a folder Templates at both places i.e., VMs & Templates and Hosts and Clusters, now its time to delete them!!,

Remove-Folder Templates

Guess what!!..

Templates is removed from both location at one shot...

I tried using the hidden folder trick, something like "get-folder -Location vm | remove-folder Temp* "

As usual this also didnt worked.. well if I use get-folder -location vm then it display the folder i am interested in deleting..

How do you insert the code section in post, with seperate box, i cant see the "Code" icon on editing tools bar

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I think your remove should have been

Get-Folder -Location vm | where {$_.Name -like "Temp*"} | Remove-Folder

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
mdwasim
Contributor
Contributor
Jump to solution

Cool, How can you figure out these things man!!,.. why cant I !!

Thanks alot...

0 Kudos