VMware Cloud Community
Ahroba
Contributor
Contributor
Jump to solution

Move VMs to a specified folder/subfolder

I need your help

I would like to migrate some VMs to a specified folder.

I need a reply in my script when i like to move VMs from a csv file to a folder or subfolder (Folder123).

I need your assistance.

Thanks

folder.JPG

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Can you change this

foreach ($VM in $VMs) {
        Move-VM -VM $VM -Destination $Folderchk[$Choice - 1] | Out-Null
    }

into this

foreach ($VM in $VMs) {
        Write-Host "Moving $VM into folder $($Folderchk[$Choice - 1])"
        Move-VM -VM $VM -Destination $Folderchk[$Choice - 1] | Out-Null
    }

Perhaps that will shed some light on what is happeing


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

View solution in original post

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

I suspect your question is about the last loop where you do the Move-VM ?

What do you want to test in the

if(xy){

statement ?


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

Ahroba
Contributor
Contributor
Jump to solution

Hi Luc,

you are right, this is what i need.

I would like to move VMs into a specific folder.

The foldername may exist several times, but under different folders/subfolders.

If I select Folder123 (DC1\Folder\Folder321\ Folder123), then the VMs should be moved there.

Thanks in advance

Reply
0 Kudos
Ahroba
Contributor
Contributor
Jump to solution

any idea...

thanks

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try the attached script


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

Ahroba
Contributor
Contributor
Jump to solution

Unfortunately, it did not work 😞

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Any error messages ?

What is displayed on the console ?


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

Reply
0 Kudos
Ahroba
Contributor
Contributor
Jump to solution

no errors.

folder.GIF

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you change this

foreach ($VM in $VMs) {
        Move-VM -VM $VM -Destination $Folderchk[$Choice - 1] | Out-Null
    }

into this

foreach ($VM in $VMs) {
        Write-Host "Moving $VM into folder $($Folderchk[$Choice - 1])"
        Move-VM -VM $VM -Destination $Folderchk[$Choice - 1] | Out-Null
    }

Perhaps that will shed some light on what is happeing


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

Reply
0 Kudos
Ahroba
Contributor
Contributor
Jump to solution

Thanks a lot.

You are great

the error was found:

foreach ($VM in $VMs) {       

Write-Host "Moving $VM into folder $($Folderchk[$Choice - 1])"       

Move-VM -VM $VM.VMName -Destination $Folderchk[$Choice - 1] | Out-Null   

}

Reply
0 Kudos
oluraghi
Contributor
Contributor
Jump to solution

When you ask for the location of the folder, is that the folder in vCenter?  Also, not sure where to specify the csv file that you are wanting to upload, and what the format should be.

Reply
0 Kudos