Hi, did you get it working? If not here is a litte sub which should do it. Just call it at the end of the main, giving a ref to @dcstruct with it: sub createmyfolders{ my $ref_dcstruct =...
See more...
Hi, did you get it working? If not here is a litte sub which should do it. Just call it at the end of the main, giving a ref to @dcstruct with it: sub createmyfolders{ my $ref_dcstruct = $_[0]; my $dc = "datacenter2"; my $datacenter_view = Vim::find_entity_view(view_type => 'Datacenter', filter=>\{name=>$dc}); foreach my $entry (@\{$ref_dcstruct}){ my $cnt = 0; my $folder_view = Vim::find_entity_view(view_type => 'Folder', begin_entity => $datacenter_view); foreach my $foldername (@\{$entry}){ $cnt++; next if $cnt<4; #skip the vmware internal folders (Datacenters, host and the datacenter itself, not nice but works) print "$cnt: Creating $foldername\n"; eval{ $folder_view = $folder_view->CreateFolder(name => \[$foldername]); $folder_view = Vim::find_entity_view(view_type => 'Folder', begin_entity => $folder_view); }; if ($@) { if($@->detail =~ /DuplicateName/){ print "$foldername allready exists, getting view of the existing one\n"; $folder_view = Vim::find_entity_view(view_type => 'Folder', begin_entity => $@->\{detail}->\{object}); } } } } } sub main{ ..... createmyfolders(\@dcstruct); }