I am moving from one virtual center to another. I have created a script that will recreate the datacenters and clusters.
I am having problems figuring out how to recreate the folders. These folders can be buried as far as 4 deep in hierarchy so even though I can do a get-folder and find the folders I am not sure how to put them back the way I they are laided out in the original VC
$1 = Get-Folder | where-object { $_.name -notlike "Discovered virtual machine"} |`
where-object { $_.name -notlike "vm"} | where-object { $_.name -notlike "Datacenters"}|`
where-object { $_.name -notlike "host"}
$1 | export-Clixml test.xml
The code above of course does not have (I don't think) the information to put the folders back in hierachy when I do -
$newfolder = Import-Clixml .\test.xml
$newfolder | foreach-Object{
Get-Folder -Name VM -Location $_.DataCenter | New-Folder -Name $_.Folder
}
Quick Note: Some of our folders are 4 levels deep
Any assistance appreciated.
Thanks
I also have to copy the resourcepool info so figuring out this step would help.
Trying this:
$new= New-Object System.Collections.ArrayList
$c = $null
$a = Get-Folder testvm
$count = 0
while(! ($c.name -eq "vm")){
$Info = "" |Select Bottom, Up, count
#$new = Get-Folder $a.name
$Info.bottom = $a
$b = $a.parentid
$c = get-folder -id $b
$Info.up = $c.name
$a = $c
$info.count = $count++
$New.add($Info)
}
I have this peice working but I still have to start the build from the vm level down