1

I have written this script to extract the PC's and servers from the AD into two differnet spreadsheets. But whenever I run the script, I'am getting the following error. Can anyone help me by pointing out on where I am going wrong.

This is the error I am getting :

Get-ADComputer : The server has returned the following error: invalid enumeration context.
At line:3 char:1
+ Get-ADComputer -filter { OperatingSystem -ne '*server*' -OR Operating ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-ADComputer], ADException
    + FullyQualifiedErrorId : The server has returned the following error: invalid enumeration context.,Microsoft.ActiveDirectory.Management.Commands.GetADComputer

Get-ADComputer : The server has returned the following error: invalid enumeration context.
At line:6 char:1
+ Get-ADComputer -filter { OperatingSystem -eq '*server*' -OR Operating ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-ADComputer], ADException
    + FullyQualifiedErrorId : The server has returned the following error: invalid enumeration context.,Microsoft.ActiveDirectory.Management.Commands.GetADComputer

Given below is the script :-

import-module ac*

Get-ADComputer -filter { OperatingSystem -ne '*server*' -OR OperatingSystemVersion -Like '*5.1*' -OR OperatingSystemVersion -Like '*6.1*' -and Enabled -eq "true"} -SearchBase 'OU=IMComputers,OU=IM,dc=image,dc=inter' -Properties '*' | Select Name,OperatingSystem,Status, OperatingSystemVersion, `
LastLogonDate,CanonicalName | Export-Csv -NoType "C:\Temp\PC's in AD" -Encoding UTF8

Get-ADComputer -filter { OperatingSystem -eq '*server*' -OR OperatingSystemVersion -Like '*5.0*' -OR OperatingSystemVersion -Like '*5.2*' -OR OperatingSystemVersion -Like '*6.0*' -OR OperatingSystemVersion -Like '*6.1*' -OR OperatingSystemVersion -Like '*6.2*' -OR OperatingSystemVersion -Like '*6.3*' -and Enabled -eq "true"} -SearchBase 'OU=IMComputers,OU=IM,dc=image,dc=inter' -Properties '*' | Select Name,OperatingSystem,Status, OperatingSystemVersion, `
LastLogonDate,CanonicalName | Export-Csv -NoType "C:\Temp\Servers in AD" -Encoding UTF8

1 Answer 1

1

Your script works when I adapt it to my organisation (it's a small one) so your are not going so wrong. But I read something about that a few years ago and thanks to G.... my friend i found Invalid Enumeration Context using powershell script to check computer accounts.

Summary : the problem is worsened if you query based on an attribute that is not indexed. The operatingSystem and also the operatingSystemVersion attributes are not indexed. Assuming you have a large number of computer objects in your domain, and you frequently query based on OS, it perhaps makes sense to make operatingSystem indexed. Another solution is to use DirectorySearcher filter with and LDAP filter instead of Get-ADComputer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.