Hello guys,
I've list of 3600 machines and i've to test connectivity and existence in AD as i'm a beginner in PS , I'd like to request some help.
I have already script to ping machines which are included in .txt file :
$currentDirectory = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition)
$inputFile = "$currentDirectory\Computers.txt"
$OutputFile = "$currentDirectory\Report.csv"
$servers = Get-Content $inputFile
$collection = $()
foreach ($server in $servers)
{
$status = @{ "ServerName" = $server; "TimeStamp" = (Get-Date -f s) }
if (Test-Connection $server -Count 1 -ea 0 -Quiet)
{
$status["Results"] = "Up"
}
else
{
$status["Results"] = "Down"
}
New-Object -TypeName PSObject -Property $status -OutVariable serverStatus
$collection += $serverStatus
}
$collection | export-csv $OutputFile -NoTypeInformation
And it returns following output :
TimeStamp | Results | ServerName |
2014-08-12T12:11:32 | Up | server1 |
I'd like to have there also info if machine exists in AD and receive output like :
TimeStamp | Results | ServerName | FoundInAD |
2014-08-12T12:11:32 | Up | server1 | YES |
2014-08-12T12:11:32 | Down | server2 | NO |
Thanks in advance