Script to get ad computer accounts and properties RRS feed

  • Question

  • Hello Team,

    The below is the script I gave to pull the computer accounts and details for AD. But I get error as 


    Get-ADComputer : The server has returned the following error: invalid enumeration context.
    At C:\Temp\Scripts\All computer details.ps1:1 char:15
    + Get-ADComputer <<<<  -Filter * -SearchBase " " |select name -ExpandProperty Name |out-file c:\temp\output\com11.txt
        + CategoryInfo          : NotSpecified: (:) [Get-ADComputer], ADException
        + FullyQualifiedErrorId : The server has returned the following error: invalid enumeration context.,Microsoft.ActiveDirectory.Management.C 


    My Script is below:



    Get-ADComputer -ldapFilter (objectclass=computer) -SearchBase " " | select name -ExpandProperty Name |out-file c:\temp\output\com11.txt

    $array = Get-Content c:\temp\output\com11.txt

    foreach ($a in $array)

    $q = $a | foreach {$_[2]}

    if ($q -ge 48 -and $q -le 57)

    $x=$a|out-file c:\Temp\output\xxxx.txt -Append



    $computers = get-content c:\Temp\output\xxxx.txt

    foreach ($comp in $computers)
    get-adcomputer -identity $comp -properties * | select cn,distinguishedName,dnshostname,dscorepropagationdata,employeeID,InstanceType,lastlogoff,lastlogon,lastlogontimestamp,logoncount,msds-authenticatedAtDC,name,objectcatehory,operatingSystem,Operatingsystem servicepack,operatingsystemversion,Samaccountname,samaccounttype,serial,streetAddress,whenchanged,whencreated |Export-Csv c:\Temp\output\computerdetails.csv


    So I want all the attributes listed for the computer that starts with two character followed by a number (eg: AH965645). 

    Note : There are more than a lakh of computer object in this OU

    Please help me to correct the script so that I can use it to pull the information required.


    Suman Rout

    • Edited by Suman Rout Wednesday, October 14, 2015 12:11 PM
    Monday, October 12, 2015 1:54 PM

All replies