This script queries Gets a list of Windows 7 Computers in domain , pings them and outputs result to Excel
#Get computers from first domain $computers = get-adcomputer -Filter 'ObjectClass -eq "Computer"' -Server domain1.com -properties operatingsystem |Where-Object -property OperatingSystem -like "Windows 7*" | Select -Expand DNSHostName #uncomment this line if you want to query a second domain and add the list of computers to ping #The += appends the output, the -Expand dnsname returns the FQDN of each computer for the resultant test-connection command (ping) #$computers += get-adcomputer -Filter 'ObjectClass -eq "Computer"' -Server domain2.com -properties operatingsystem |Where-Object -property OperatingSystem -like "Windows 7*" | Select -Expand DNSHostName #Create a New Excel Object for storing Data $excelworksheet = New-Object -comobject Excel.Application $excelworksheet.visible = $True $b = $excelworksheet.Workbooks.Add() $c = $b.Worksheets.Item(1) # Create the title row $c.Cells.Item(1,1) = "Machine Name" $c.Cells.Item(1,2) = "OS" $d = $c.UsedRange $d.Interior.ColorIndex = 23 $d.Font.ColorIndex = 2 $d.Font.Bold = $True $intRow = 2 # Run through the Array of Computers foreach ($item in $Computers) { if (test-connection -computername $item -Count 1 -quiet) { Write-Host -ForegroundColor Green $item $SN = 'Online' #$i + "`n" + "================" $c.cells.item($intRow,1) = $item $c.cells.item($intRow,2) = $SN $intRow++ } else { Write-Host -ForegroundColor Yellow $item " Offline" $SN = 'Offline' $c.cells.item($intRow,1) = $item $c.cells.item($intRow,2) = $SN $intRow++ } } $intRow++ # Save workbook data $b.SaveAs("C:\temp\britV8\Checklist.xlsx")