Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #initialize/configure AD query
- $strCategory = "computer"
- $objDomain = New-Object System.DirectoryServices.DirectoryEntry
- $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
- $objSearcher.SearchRoot = $objDomain
- $objSearcher.Filter = ("(objectCategory=$strCategory)")
- $colProplist = "name"
- foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
- $colResults = $objSearcher.FindAll()
- #
- #where store all the data
- $data = @()
- #where store all the computer
- $comp = @()
- #custom obj with some propietes. this update the data
- $myobj = "" | select name
- #get the info from AD and store into an array
- foreach ($objResult in $colResults)
- {
- $objComputer = $objResult.Properties;
- $comp += $objComputer.name;
- }
- #bi array where save all the results. a rofl for the size :s
- $result = New-Object 'object[,]' 100,999
- #counter of array
- $row = 0
- $column = 0
- #quit flag
- $quit = 0
- #a non-stop loop. when user say stop! :)
- while( $quit -eq 0 )
- {
- #get date to a string
- #$date = get-date -format "%h:%m:%s-%d%M%y"
- #$date = $date.ToString()
- #add propiety to myobj
- $myobj | Add-Member -type noteproperty -name $column -value @()
- foreach ($i in $comp)
- {
- $myobj.name = $i
- #check network connection
- if( (Test-Connection -ComputerName $myobj.name -quiet) -eq $True )
- {
- $result[$row,$column] = 'true'
- }
- else
- {
- $result[$row,$column] = 'false'
- }
- for( $c = 0; $c -le $column; $c++ ) {
- $myobj.$c = $result[$row,$c]
- }
- #increase array[x, ] counter
- $row++
- $data += $myobj | Select-Object *
- $data | ft
- }
- #save to csv
- $data | Export-Csv report_adcomputer_response.csv -notype -force
- #bkp, why not ? :)
- $data | Export-Csv report_adcomputer_response.csv.bkp -notype -force
- #increase array[x, ] counter
- $column++
- #reset array[ ,x] counter
- $row = 0
- #clear the object
- $data = @()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement