title: Problem with powershell script for AD server Status
body: <p>I have a script that can have a list of AD servers (with Get-ADComputer) and the results goes to a TXT file. I don't know how to only have Online Servers only. I only need their names.</p>
  
  <p>I tried to do some IF {} Else{} with the cmdlet Test-Connection -CN $Server but it doesn't work (I'm probably doing it wrong). Here is my code :</p>
  
  <pre><code>$TXTFile = "C:\Scripts\Serv.txt"
  
  $TXTOutput = @()
  
  Write-Host "INFO: Finding servers from AD"
  
  $Servers = Get-ADComputer -Filter {OperatingSystem -like "*server*" -and Enabled -eq $true} | SORT Name
  Write-Host "INFO:"$Servers.Count"Records found"
  
  ForEach ($Server in $Servers) {
  
      $ServerHash = $NULL
      $ServerHash = [ordered]@{
          "Servers Name" = $Server.Name
      }
      $TXTOutput += New-Object PSObject -Property $ServerHash
  }
  $TXTOutput
  </code></pre>
  
  <p>I want, if possible, to have all of my AD Online Servers name in a TXT file. For now I only have all of my servers (Online and Offline). It's my first post so sorry if I made it wrong !</p>