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.
"An exception occurred during a Ping request."
error.