# demo file: "C:\Documents and Settings\hrottenberg\My Documents\WindowsPowerShell\scripts\book\wikideploy.txt" param ( $InputFile, $Server ) Connect-VIServer -Server $Server $text = Get-Content $InputFile $tree = @{} # Hashtable to store hierarchy $DataCenterIndex, $FolderIndex, $SubFolderIndex = 0 $Datacenter, $Folder, $SubFolder = $null $FolderRoot = Get-Folder -NoRecursion # New DCs are created here for ( $i = 0; $i -lt $text.length; $i++ ) { # Alphanumeric text in first column is a Datacenter if ( $text[$i] -match '^\w+' ) { $DataCenterIndex = $i $tree[$DataCenterIndex] = @{} } # One tab followed by text is a Folder elseif ( $text[$i] -match '^\t\w+' ) { $FolderIndex = $i $tree[$DataCenterIndex][$FolderIndex] = @{} } # Two tabs followed by text is a SubFolder elseif ( $text[$i] -match '^\t{2}\w+' ) { $SubFolderIndex = $i $tree[$DataCenterIndex][$FolderIndex][$SubFolderIndex] = @{} } } $tree.Keys | ForEach-Object { $DataCenterIndex = $_ $DatacenterName = $text[$_].Trim() # Remove leading tab Write-Host "Datacenter: $DatacenterName" -ForegroundColor Red $dc = New-Datacenter -Name $DatacenterName -Location $FolderRoot $tree[$_].Keys | ForEach-Object { $FolderIndex = $_ $FolderName = $text[$_].Trim() Write-Host "`tFolder: $FolderName" -ForegroundColor Blue $Folder = New-Folder -Name $FolderName -Location $dc $tree[$DataCenterIndex][$FolderIndex].Keys | ForEach-Object { $SubFolderName = $text[$_].Trim() Write-Host "`t`tSubFolder: $SubFolderName" -Fore Green $SubFolder = New-Folder -Name $SubFolderName -Location $Folder } } }