Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

the server has returned the following error: invalid enumeration context powershell.

$
0
0

I am getting an error while executing the below Powershell script. I have a huge database of users in active directory. This script gives me desired results but it times out after around 8000 users extracted. This is the error I am getting is the server has returned the following error: invalid enumeration context powershell. Please help.

Get-ADUser -Filter * -SearchBase "OU=abc,DC=xyz,DC=abc" -Properties cn, 

samaccountname, displayName, givenName, middlename, sn, mail, employeeID | Foreach-Object {
    $group = ""
    Get-ADPrincipalGroupMembership $_.SamAccountName | Foreach-Object { 
        if (($_.Name -eq "maple") -or ($_.Name -eq "oak") -or ($_.Name -eq "tree"))
        {
            $group += $_.Name + ","
        } 
    }
    if ($group -eq "")
    {
        $group = "other"
    }
    else 
    {
        $group = $group.Substring(0, $group.Length - 1)
    }   
    New-Object -TypeName PSObject -Property @{
        System_Role = "NONE"
    External_Person_Key = $_.cn
    User_ID = $_.samAccountName
    Passwd = "*****"
    PreferredName = $_.displayName
    FirstName = $_.givenName
    MiddleName = $_.middleName
    LastName = $_.sn
    Email = $_.mail
    Student_ID = $_.employeeID
    Institution_Role = $group
    } | Select-Object System_Role, External_Person_Key, User_ID, Passwd, PreferredName, FirstName , MiddleName, LastName, Email, Student_ID, Institution_Role          
} | Export-Csv -Path "c:\users.csv" 


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>