title: Powershell Get-ADUser - invalid enumeration context error
body: <p>I'm having issues getting all AD users in my work environment.
  It runs for about 30 minutes before displaying the following error below:</p>
  
  <pre><code>    Get-ADUser : The server has returned the following error: invalid enumeration context.
  At line:3 char:19
  +                   Get-ADUser  -filter * -Properties * |
  +                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [Get-ADUser], ADException
      + FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.GetADUser
  </code></pre>
  
  <p>I did some research and found out that MaxEnumContextExpiration = 30 Mins and figured that's the reason why it stops running at 30 Minutes.</p>
  
  <p>My question is: Is there a quicker way to pull all the users in my work environment(about 60k employees)along with all their info(Name, Samaccountname,Description, Group Membership,Account Status, etc...)</p>
  
  <p>This is the script I currently have:</p>
  
  <pre><code>              Import-module activedirectory
                $daTA=@(
                Get-ADUser  -filter * -Properties * |  
                Select-Object @{Label = "FirstName";Expression = {$_.GivenName}},  
                @{Name = "LastName";Expression = {$_.Surname}},
                @{Name = "Full address";Expression = {$_.StreetAddress}},
                @{Name = "Fullname";Expression = {$_.Name}},
                @{Name = "LogonName";Expression = {$_.Samaccountname}},
                @{Name = "City";Expression = {$_.City}}, 
                @{Name = "State";Expression = {$_.st}}, 
                @{Name = "Post Code";Expression = {$_.PostalCode}}, 
                @{Name = "Country/Region";Expression ={$_.Country}},
                @{Name = "MobileNumber";Expression = {$_.mobile}},
                @{Name = "Phone";Expression = {$_.telephoneNumber}}, 
                @{Name = "Description";Expression = {$_.Description}},
                @{name=  "OU";expression={$_.DistinguishedName.split(',')[1].split('=')[1]}},
                @{Name = "Email";Expression = {$_.Mail}},
                @{Name = "MemberOfGroups";e= { ( $_.memberof | % { (Get-ADGroup $_).Name }) -join “,” }},
                @{Name = "Primary Group";Expression= {$_.primarygroup  -replace '^CN=|,.*$'}},
                @{Name = "UserPrincipalName";Expression = {$_.UserPrincipalName}},
                @{Name = "LastLogonTimeSTamp";Expression = {if(($_.lastLogonTimestamp -like '*1/1/1601*' -or $_.lastLogonTimestamp -eq $null)){'NeverLoggedIn'} Else{[DateTime]::FromFileTime($_.lastLogonTimestamp)}}},
                @{Name = "Account Status";Expression = {if (($_.Enabled -eq 'TRUE')  ) {'Enabled'} Else {'Disabled'}}},
                @{Name = "LastLogonDate";Expression = {if(($_.lastlogondate -like '*1/1/1601*' -or $_.lastlogondate -eq $null)){'NeverLoggedIn'} Else{$_.lastlogondate}}},
                @{Name = "WhenUserWasCreated";Expression = {$_.whenCreated}},
                @{Name = "accountexpiratondate";Expression = {$_.accountexpiratondate}},
                @{Name = "PasswordLastSet";Expression = {([DateTime]::FromFileTime($_.pwdLastSet))}},
                @{Name = "PasswordExpiryDate";Expression={([datetime]::fromfiletime($_."msDS-UserPasswordExpiryTimeComputed")).DateTime}},
                @{Name = "Password Never";Expression = {$_.passwordneverexpires}},
                @{Name = "HomeDriveLetter";Expression = {$_.HomeDrive}},
                @{Name = "HomeFolder";Expression = {$_.HomeDirectory}},
                @{Name = "scriptpath";Expression = {$_.scriptpath}},
                @{Name = "HomePage";Expression = {$_.HomePage}},
                @{Name = "Department";Expression = {$_.Department}},
                @{Name = "EmployeeID";Expression = {$_.EmployeeID}},
                @{Name = "Job Title";Expression = {$_.Title}},
                @{Name = "EmployeeNumber";Expression = {$_.EmployeeNumber}},
                @{Name = "Manager";Expression={($_.manager -replace 'CN=(.+?),(OU|DC)=.+','$1')}}, 
                @{Name = "Company";Expression = {$_.Company}},
                @{Name = "Office";Expression = {$_.OfficeName}}
                )
                $DAta | Sort LastLogondate -Descending | 
                Export-Csv -Path c:\adusers.csv -NoTypeInformation
  </code></pre>