title: Getting services on remote servers through powershell
body: <p>I've been trying to develop a powershell script to query a particular OU in AD and then get the services on each of those services including name, status, startmode, startname, description. I've gotten really close but not getting the results I expect.  Can someone help?  </p>
  
  <p>The problem is if I run the command for one server specifically, I get the results I want.  If I run for all servers in an OU it does not find any unique startnames (only the local accounts).  I want a single CSV with the server name first</p>
  
  <p><strong>Script for single computer (getting results we want):</strong></p>
  
  <pre><code>$ServerName = “server01”
  
  Get-WmiObject win32_service -ComputerName $servername | Select @{N="ServerName";E={$ServerName}}, Name, Status, StartMode, StartName, description | Export-Csv "server_Services.csv" -NoTypeInformation
  </code></pre>
  
  <p><strong>Script for querying OU (only returning services with local accounts):</strong></p>
  
  <pre><code>$ServerOU = 'OU=Servers,DC=some,DC=domain'
  
  $ServerList = Get-QADComputer -SearchRoot $ServerOU -SearchScope Subtree
  
  $ServerList | ForEach {   
        $ServerNameTemp = $_.Name
        Get-WMIObject Win32_Service | 
        Select @{N="ServerName";E={$ServerNameTemp}}, StartName, Name, StartMode, Status, description
        } | Export-Csv -NoTypeInformation $ExportFile
  </code></pre>