title: Output file doesn't match Write-Host
body: <p>When I <code>Write-Host</code> from my .ps1 file I see:</p>
  
  <pre class="lang-none prettyprint-override"><code>Parentfolder &gt;&gt; ChildFolder
  </code></pre>
  
  <p>When I output to a file, I see:</p>
  
  <pre class="lang-none prettyprint-override"><code>ParentFolder
  &gt;&gt;
  ChildFolder
  </code></pre>
  
  <p>I am using a simple <code>write-host ($childgroup.name), "&gt;&gt;", ($object.samaccountname)</code> </p>
  
  <p>When I try to output the same information using <code>Return</code>, <code>Out-File</code>, <code>Export to CSV</code>, etc... I get <em>3</em> lines for what <code>Write-Host</code> prints as a <em>single line</em>.</p>
  
  <p>I just want the output file to be in the same format as the <code>Write-Host</code> output. </p>
  
  <p>as requested:</p>
  
  <pre><code>function getchildgroups($groupname) {
  
      # Get initial group details and members
      $childgroup = get-adgroup $groupname -properties member
  
      # Only continue if this group has members
      if (($childgroup.member).count -gt 0) {
  
          # Loop through each member of the group
          foreach ($memberobject in $childgroup.member) {
  
              try {
                  $object = get-adobject $memberobject -properties *;
  
                  # If the member of the group is another group
                  if ($object.objectclass -eq "group")  {
  
                      # Print it to the screen
  
                      write-host ($childgroup.name),"&gt;&gt;", ($object.samaccountname) 
                     #$cgname = $childgroup.name
                      #$objname =$object.samaccountname
                      #Return (($cgname, "&gt;&gt;", $objname)) &gt;&gt; 
  c:\Temp\NestedGroups.txt
  
                      # Recursive lookup the members of the sub-group (if 
  not self-nested)
                      if ($memberobject -ne $object.distinguishedname) {
  
                          getchildgroups($object.distinguishedname);
                      }
                  }
              } catch {}
          }
      }
  }
  
  # Run the function with your group name
  $Groups = Get-Content C:\temp\ListOfFolders.txt
  Foreach ($Group in $Groups){
  getchildgroups("$group") 
  }
  </code></pre>