Windows Vista Forums

Why is my foreach loop only looping through the first object in th
  1. #1


    Jacob Sampson Guest

    Why is my foreach loop only looping through the first object in th

    $domain = new-object
    system.directoryservices.directoryentry("LDAP://ou=domain
    controllers,dc=mhco,dc=mizehouser,dc=com")

    $searcher = new-object System.DirectoryServices.DirectorySearcher($domain)
    $searcher.filter = "(objectCategory=computer)"
    $searcher.pagesize=1000
    $searcher.propertiesToLoad.Add("name")
    $computers = $searcher.findall()
    foreach ($computer in $computers)
    {
    $computername = $computer.properties.name
    $ping = gwmi win32_pingstatus -f "Address = '$computername'"
    if ($ping.StatusCode -eq 0)
    {
    }
    }




      My System SpecsSystem Spec

  2. #2


    Jacob Sampson Guest

    RE: Why is my foreach loop only looping through the first object in th

    Sorry I got it figured out. I had the wrong default gateway and most of the
    servers were remote.

    Thanks

    "Jacob Sampson" wrote:

    > $domain = new-object
    > system.directoryservices.directoryentry("LDAP://ou=domain
    > controllers,dc=mhco,dc=mizehouser,dc=com")
    >
    > $searcher = new-object System.DirectoryServices.DirectorySearcher($domain)
    > $searcher.filter = "(objectCategory=computer)"
    > $searcher.pagesize=1000
    > $searcher.propertiesToLoad.Add("name")
    > $computers = $searcher.findall()
    > foreach ($computer in $computers)
    > {
    > $computername = $computer.properties.name
    > $ping = gwmi win32_pingstatus -f "Address = '$computername'"
    > if ($ping.StatusCode -eq 0)
    > {
    > }
    > }
    >

      My System SpecsSystem Spec

Why is my foreach loop only looping through the first object in th problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
err object and looping Lee VB Script 4 25 Feb 2009
Foreach and if else loop Jsimpson PowerShell 2 17 Jun 2008
method Error in foreach loop Wilson PowerShell 2 13 Jun 2008
foreach, foreach-object & begin/process/end scriptblock clauses... Clint Bergman PowerShell 12 16 May 2007
Difference in semantics of for, foreach and foreach-object Andrew Watt [MVP] PowerShell 3 26 Jan 2007