title: AD query Powershell and Export to txt file
body: <p>Can someone help me?</p>
  
  <p>I have to create a <code>.txt</code> file with the following format:</p>
  
  <pre><code>user("SamAccountName","GivenName Surname"){}
  </code></pre>
  
  <p>I'm able to create just this:</p>
  
  <pre><code>#Get AD Users Info
  cls
  $SamAccountName = New-Item 'c:\SamAccountName.txt' -type file -Force
  
  Get-ADUser -Filter * -Properties SamAccountName | 
      select -First 15 | Sort-Object SamAccountName |
           Format-Table SamAccountName | Out-File $SamAccountName
  
  
  $content = Get-Content $SamAccountName
  $content | Foreach {$_.TrimEnd() } | where {$_ -ne ""} | Select-Object -Skip 3 | Set-Content $SamAccountName
  
  
  #Write quotes (make it nice and readable!)
  $ACTIVEDIRECTORY = New-Item 'c:\ACTIVEDIRECTORY.lst' -type file -Force
  
  Clear-Content $ACTIVEDIRECTORY
  
  $quotes= '"'
  
  (Get-Content $SamAccountName) |     
      ForEach-Object {Add-Content $ACTIVEDIRECTORY "$quotes$_$quotes"}
  
      Get-Content $ACTIVEDIRECTORY
  </code></pre>
  
  <p>This give me this result: </p>
  
  <pre><code>"GivenName"
  "GivenName"
  "GivenName"
  </code></pre>