title: Powershell Nested Hashtables - Export to file
body: <p>Im pulling out information from AD to output alot of information to be handled at a later point.</p>
  
  <p>I need to export this to a csv or something so i can have a rollback ( in effect import file so i can handle each object like i can with the hashtable below. Especially that inside $_.MemberOf).</p>
  
  <p>The hashtable im struggling with handling is:</p>
  
  <pre><code>$logging1 = @{
  MemberOf="$users.MemberOf"
  OriginalOU="$Ou.DistinguishedName"
  DisabledWhen="$descriptionDisabled"
  }
  $logging = @{$users.SamAccountname = $logging1}
  </code></pre>
  
  <p>what the rest of the script does is(that isnt pasted ) is:</p>
  
  <p>iterate through a bunch of ou's. Getting users last logged in -90 days ago or more then passing them to the HashTable in question which i like to append to a file to be imported at a later time.</p>
  
  <p>I have been googling for hours without getting somewhere</p>
  
  <p>here is the complete script:</p>
  
  <pre><code>import-module ActiveDirectory
  $descriptionDisabled = get-date -Format yyyyMMdd
  $Loggdir = "C:\temp"
  $array = @{}
  $loggname = get-date -f yyyyMMdd
  $90days = ((get-date).AddDays(-90))
  $searchBase = 'OU=someou4,OU=someou3,OU=someou2,OU=someou1,DC=name,DC=NO'
  $ExclusionList = Someexlutions
  $OUlist = Get-ADOrganizationalUnit -SearchBase $searchBase 
  foreach ($Ou in $OUlist)
  {
  $ExpiredADusers = get-aduser -Filter {(LastlogonDate -le $90days) 
                                        -and (Enabled -eq $True)}
                               -SearchBase $ou.distinguishedname
                               -Properties * 
  #Get information about every user and their groupmembership
  foreach ($Users in $ExpiredADusers)
      {
      $users = get-aduser -Identity $users.SamAccountName
                          -Properties * 
               | Select-Object -Property SamAccountName, MemberOf, 
                                         DistinguishedName, ObjectGUID
      $logging =  @{$person.SamAccountName = @{
      MemberOf=$person.MemberOf;
      OriginalOU=$Ou.DistinguishedName;
      DisabledWhen="$descriptionDisabled"}}
      $Array += $Logging   
  
      }         
  }
  
  $array | export-clixml -path somepath -noclobber      
  </code></pre>
  
  <p><strong>EDIT SOLVED</strong>
  Solved problem and original script in question has been updated to handle Nested hashtables</p>
  
  <p><strong>Original problem</strong>
  I think you can understand what im trying to do.
  Im making a rollback file incase needed.</p>
  
  <p>So the exported file need to be easy to import. when using hashtables you can use . notations and each objects under memberof is treated as an object</p>
  
  <p>What the rollback needs is so i can iterate through the imported info to move the user back to its original OU placement and restore membership</p>