title: Generating array from multiple folder paths
body: <p>Alright, I am confusing my self on how to get this to work. I have several folder locations that have multiple sub-folders. These sub-folders are all named after hosts on our network. So I am working on a script to validate the contents of the folders for auditing purposes. I can not seem to generate a usable list that has the system name derived from the folder name and the full path name. I.G.</p>
  
  <pre><code>Name        Path
  ----        ----
  system1     \\path\rootfolder1\system1
  system2     \\path\rootfolder1\system2
  system3     \\path\rootfolder2\system3
  </code></pre>
  
  <p>I get the root folders from a CSV file as the folders are not all in one location and I do not need to use every folder time I run the report.</p>
  
  <pre><code>#Path to folder repository. Folder names must be the systems host name. 
  $list_paths = (Import-Csv 'C:\CVS\path\Paths.csv').path
  
  #list arrays
  $list = @()
  $list2= @()
  
  #Counters
  $p_count = 0
  $l_count = 0
  
  
  #Generates array (list) of folder paths
  Foreach ($p1 in $list_paths){
  $l_count ++
  $listx1 = Get-ChildItem $p1 | Where-Object {$_.PSIsContainer} | Foreach-object {$_.FullName}
  $list += $listx1
  }
  
  #Generates array (list) of system names from folder
  ForEach ($p2 in $list){
  $p_count ++
  Write-Host $p2
  $listx2 = split-path -path $p2 -leaf
  $list2 += $listx2
  }
  
  
  $Output = New-Object PSObject -Property @{
          "Name" = $list
          "Path" = $list2
          }
  
  Write-Host ($Output | Format-table | Out-String)
  
  Write-Host Number of root folders
  Write-Host $l_count
  Write-Host Number of host folders
  Write-Host $p_count'
  </code></pre>
  
  <p>So when I run the script <code>$output</code> produces this instead of the format I want above.</p>
  
  <pre><code>Name
  ----
  {\\path\rootfolder1\system1, \\path\rootfolder2\system2, \\path\root...}
  </code></pre>
  
  <p>I know I am doing something wrong but I can seem to figure out what.</p>