4

We're switching to WDS for deployment, so I'm writing a powershell script that will ping a computer and if it responds, get its MAC address and set the netbootGUID field in Active directory. It runs and works...for a while and then returns:

Get-ADComputer : The server has returned the following error: invalid enumeration context. At \Path\To\Scripts\setNetbootGUIDremoteComputers.ps1:3 char:15

  • get-adcomputer <<<< -Filter * -searchbase "OU=Somehwere,DC=My,DC=AD,DC=TLD" -ResultSetSize $null | foreach-object {
    • CategoryInfo : NotSpecified: (:) [Get-ADComputer], ADException
    • FullyQualifiedErrorId : The server has returned the following error: invalid enumeration context.,Microsoft.ActiveDirectory.Management.Commands.GetADComputer

This is the script:

import-module ActiveDirectory

get-adcomputer -Filter * -searchbase "OU=Somewhere,DC=MY,DC=AD,DC=TLD" -ResultSetSize $null | foreach-object {

    $strComputer = $_.Name
    $ping = new-object System.Net.NetworkInformation.Ping
    $Reply = $ping.send($strComputer)
    
    if ($Reply.status –eq “Success”){
            $colItems = GWMI -cl "Win32_NetworkAdapterConfiguration" -name "root\CimV2" -comp $strComputer -filter "IpEnabled = TRUE"
    
            ForEach ($objItem in $colItems) {
                $MAC = $objItem.MacAddress.Replace(":", "") 
                Write-Host "Machine Name: " $strComputer
                Write-Host "MAC Address:" $MAC                          
                [guid]$nbGUID = "00000000-0000-0000-0000-$MAC"        
                $comp = get-adcomputer $strComputer -Properties netbootGUID
                $comp.netbootGUID = $nbGUID.ToByteArray()
                set-adcomputer -Instance $comp
                write-output "$strComputer" | out-file -filePath c:\somewhere\guidSet.txt -append
            }
    }
    else {
        write-output "$strComputer" | out-file -filePath c:\somewhere\offline.txt -append
    }
    $Reply = ""


     
}

I have no idea why I'm getting that error or what it means. My GoogleFu is failing me today.

9
  • 1
    Try wrapping it in a Try/Catch statement ala Ben's example in my question here. It might give you more info to troubleshoot since it's running for a bit before choking. It might be just a single result that's causing it to crap out on you. Jun 24, 2011 at 2:17
  • Curious. How many objects is this likely to return?
    – uSlackr
    Mar 14, 2012 at 13:09
  • Do you know which computer is throwing this error? I suspect a permissions issue. I've run trough over 2000 of our machines and have only seen the "An exception occurred during a Ping request." error.
    – jscott
    Mar 14, 2012 at 13:19
  • @uSlackr thousands
    – MDMarra
    Mar 14, 2012 at 13:20
  • @jscott Unfortunately, no. But it seemed to happen at different positions each time. I ended up just creating sub-OUs and running it each of them with 1-2k objects a piece. This environment doesn't exist anymore, so I can't really follow up :(
    – MDMarra
    Mar 14, 2012 at 13:21

4 Answers 4

1

NB: I'm not a PS guru

My google fu turned up the following link.

In short, I think it has something to do with your -ResultSetSize $null portion of the script. In the link, the OP used -notlike "*"instead of the -eq "$Null"

Maybe play with that portion of the script and see what happens.

1
  • Unfortunately, the -ResultSetSize isn't a filter, so the -notlike switch doesn't apply to it :( The get-help page for get-adcomputer says that -eq $NULL is the correct way to say that there is no max result size. Thanks for the try though.
    – MDMarra
    Jun 24, 2011 at 0:22
1

I like the get-adcomputer and quest-active directory commands for cases where i need a lot of information on a server, but otherwise stick with the active-directory commands dsquery and dsget, because I find the get-adcomputer and especially the quest commands unnecessarily slow, though something may be requiring you not to use these ds commands. If you do have access to these commands, this might be worth a shot, even if it just gives you a different error message, as it by-passes the use of get-adcomputer and existing method of determining ping-ability ( kind of Mickey-Mouse, but sometimes this way provides additional information ) -

dsquery computer ou=Somewhere,dc=My,dc=AD,dc=TLD | ?{$_ -imatch "cn=([^,]+,),"} | % {
    $your_computer = $Matches[1]
    $cannot_ping_computer = $false

    # similarly for the ping command, but should be it's own little function
    ping $your_computer | ?{$_ -imatch "\s*Packets: Sent = (\d+), Received = (\d+)" }|% {
      # or whatever conditions you find satisfactory
      if ($Matches[1] -ne $Matches[2]) $cannot_ping_computer = $true
    }
    if ( $cannot_ping_computer ) {
      #command to jump to next element in pipe, I cannot recall >.<      
    }
    # rest of your code...
}

Been out of work for past couple months, and have no access to a Windows machine, so the code is off the top of my head, but I hope it works for you. Seems right.

I hope you solved the problem, but if not, I hope this can help in some way.

Good luck! :)

2
  • I really don't think that running dsquery computer -limit 0 is going to be faster than running a PowerShell query with a filter. The AD has well over 10k computer objects in it. Your implementation would return a result for every single computer and then evaluate whether or not it belongs in the set. I appreciate the attempt, but I'm looking for a pure native PowerShell implementation.
    – MDMarra
    Nov 19, 2011 at 19:12
  • Mark, you are correct, and I updated the suggestion to filter as your task requires. This should eleviate concerns of efficiency on the 10k objects. I think the only advantage is handling small strings instead of objects with unused data, and that you can potentially get alternative information on the issue and, or, by-pass the current issue. Either way, good luck! :)
    – kikuchiyo
    Nov 19, 2011 at 19:47
1

I would try playing with the ResultPageSize parameter based on this post. Perhaps setting it to a few hundred results at a time.

1
  • The site can't be reached.? Anyway, does the -ResultPageSize will only limit the result up to that amount we specify not the complete result? Oct 1, 2020 at 3:20
0

I never resolved this. I ended up making OUs under the larger container and running this against 1k accounts at a time.

Unfortunately, this will remain a mystery, since this environment no longer exists.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .