title: Trying to Pull list of computers from AD via powershell
body: <p>So I'm trying to pull a list of computers from AD into a .csv file. I'm trying to pull the cn, description, distinguishedName, operatingSystem, whenCreated, and whenChanged fields using powershell.</p>
  
  <p>The code I'm using is this:</p>
  
  <pre><code># Start of script
  
  Cls
  
  $DomainRootPath='LDAP://DC=&lt;name&gt;,DC=ORG'
  
  $adsearch = New-Object  DirectoryServices.DirectorySearcher([adsi]$DomainRootPath)
  $adsearch.PageSize = 1000
  $adsearch.filter = ("(objectCategory=Computer)")
  
  $adsearch.PropertiesToLoad.AddRange(@("cn"))
  $adsearch.PropertiesToLoad.AddRange(@("description"))
  $adsearch.PropertiesToLoad.AddRange(@("distinguishedName"))
  $adsearch.PropertiesToLoad.AddRange(@("operatingSystem"))
  $adsearch.PropertiesToLoad.AddRange(@("whenCreated"))
  $adsearch.PropertiesToLoad.AddRange(@("whenChanged"))
  
  
  $computers = $adsearch.findall()
  
  $computers.Count
  
  $report = @()
  
  foreach ($objResult in $computers)
  {
  
  $objItem = $objResult.Properties
  
  $temp = New-Object PSObject
  
  $temp | Add-Member NoteProperty cn $($objitem.cn)
  $temp | Add-Member NoteProperty description $($objitem.description)
  $temp | Add-Member NoteProperty distinguishedName $($objitem.distinguishedName)
  $temp | Add-Member NoteProperty operatingSystem $($objitem.operatingSystem)
  $temp | Add-Member NoteProperty whenCreated $($objitem.whenCreated)
  $temp | Add-Member NoteProperty whenChanged $($objitem.whenChanged)
  
  
  $report += $temp
  }
  
  $csvfile="AD-All-Computers.csv"
  
  $report | export-csv -notypeinformation $csvfile
  "Wrote file for All Computers"
  </code></pre>
  
  <p>Now This code does create the .csv with the correct fields for the column names. However it only pulls the cn and description of each computer in the directory. All of the other fields are blank when it populates the .csv</p>
  
  <p>Not sure what is going wrong in the code as I get no error any help is much appreciated. </p>
  
  <p>On a side note I am running Windows 2008 R2 server and unable to run powershell 2.0 cmdlets in my environment due to certain systems preventing us to be able to confgiure AD to do so.</p>