none
copyAD suite of Powershell scripts RRS feed

  • Question

  • This series of scripts has worked wonderful.

    https://gallery.technet.microsoft.com/scriptcenter/site/search?f%5B0%5D.Type=User&f%5B0%5D.Value=uSlackr

    The one exception is the one to pull users.  It is a large domain and I suspect that may be the issue but I am not sure.

    Below is the script.

    # user-export - 9/14/11
    # Copyright Greg Martin gmartin@gmartin.org
    # License MS-LPL 
    #s# 
    # Part of the copyAD suite of Powershell scripts
    # Exports selected user attributes to a csv file
    #
    #Import-Module ActiveDirectory -ErrorAction SilentlyContinue  
    
    $basedn = 'DC=MY,DC=Domain,DC=GOV'
    $outcsv = 'c:\scripts\users3.csv'
    
    # Note: there is a long string of attributes in the next line
    get-aduser -filter * -searchbase $basedn -properties * |select CanonicalName,CN,Company,Department,Description,DisplayName,DistinguishedName,Division,EmailAddress,EmployeeID,EmployeeNumber,GivenName,HomeDirectory,info,Initials,mail,mailNickname,Name,Office,OtherName,SamAccountName,ScriptPath,State,StreetAddress,Surname,Title,UserPrincipalName     | export-csv $outcsv
    


    After 30 to 40 minutes it gives the below error.

    get-aduser : The server has returned the following error: invalid enumeration context.
    At C:\Temp\Copy AD to test Lab\X-3-user-export.ps1:14 char:1
    + get-aduser -filter * -searchbase $basedn -properties * |select CanonicalName,CN, ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Get-ADUser], ADException
        + FullyQualifiedErrorId : ActiveDirectoryServer:0,Microsoft.ActiveDirectory.Management.Commands.GetADUser

    Thanks in advance

    Friday, December 19, 2014 1:50 PM

Answers

  • You can try adding -resultSetSize and -Resultpagesize to the query to try to avoid the timeout.  You may also have issues with reources on the AD server.

    Be careful that you local disk has ample space for the file.


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, December 19, 2014 2:36 PM
    • Marked as answer by Lishron Friday, December 19, 2014 2:59 PM
    Friday, December 19, 2014 2:34 PM

All replies

  • The one exception is the one to pull users.  It is a large domain and I suspect that may be the issue but I am not sure.

    My guess is that you're correct. Here's some information (the article is about Get-ADComputer, but the information is still relevant):

    http://blogs.technet.com/b/askds/archive/2012/04/14/saturday-mail-sack-because-it-turns-out-friday-night-was-alright-for-fighting.aspx#invalidenumeration

    I recommend dropping the wildcard on properties and only returning the properties you're interested in. Perhaps that will help.


    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    Friday, December 19, 2014 2:27 PM
  • Post questions to the author of the script.


    ¯\_(ツ)_/¯

    Friday, December 19, 2014 2:29 PM
  • You can try adding -resultSetSize and -Resultpagesize to the query to try to avoid the timeout.  You may also have issues with reources on the AD server.

    Be careful that you local disk has ample space for the file.


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, December 19, 2014 2:36 PM
    • Marked as answer by Lishron Friday, December 19, 2014 2:59 PM
    Friday, December 19, 2014 2:34 PM
  • Thanks very much  

    Friday, December 19, 2014 3:00 PM
  • You are welcome - which one worked?

    ¯\_(ツ)_/¯

    Friday, December 19, 2014 3:05 PM
  • This was the one that worked

    You suggested removing the wild card from properties and that was the solution.  

    Of course as i re read this i now realize i may not need the select function so i will try it without next.  

    get-aduser -filter * -searchbase $basedn -properties CanonicalName,CN,Description,DisplayName,DistinguishedName,EmailAddress,GivenName,Initials,instanceType,mail,Name,Office,physicalDeliveryOfficeName,PrimaryGroup,primaryGroupID,SamAccountName,sAMAccountType,sn,Surname,UserPrincipalName  |select CanonicalName,CN,Description,DisplayName,DistinguishedName,EmailAddress,GivenName,Initials,instanceType,mail,Name,Office,physicalDeliveryOfficeName,PrimaryGroup,primaryGroupID,SamAccountName,sAMAccountType,sn,Surname,UserPrincipalName | export-csv $outcsv

    THANKS!

    Friday, December 19, 2014 5:23 PM
  • Reducing pagesize will improve performance and reduce resource demand.  Start with a pagesize of 500 or less.  This will allow for faster buffering and turn around and will redicue demand on the server by as much as 50%

    To prevent server demands use resultsetsize to limit the returned records for testing.  I usually set it at 100 until I am done testing.


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, December 19, 2014 9:17 PM
    Friday, December 19, 2014 5:39 PM
  • Reducing pagesize will improve performance and reduce resource demand.  Start with a pagesize of 500 or less.  This will allow for faster buffering and turn around and will redicue demand on the server by as much as 50%


    ¯\_(ツ)_/¯

    I am not understanding you.

    Friday, December 19, 2014 5:56 PM
  • OHHHH

    Thanks!

    Friday, December 19, 2014 6:11 PM
  • Reducing pagesize will improve performance and reduce resource demand.  Start with a pagesize of 500 or less.  This will allow for faster buffering and turn around and will redicue demand on the server by as much as 50%


    ¯\_(ツ)_/¯

    I am not understanding you.

    The default pagesize is 1000.  The commands use that unless you set it different.  "-ResultPageSize 500" will cause the command to return results after it gather each 500 records.  On large AD installations this will reduce the memory requirements on the server for buffering.  Results are only returned after a page is filled so it also increases the response and allows for matching the client, network and sever for optimal performance.  You can adjust from about 250 to 1000 to find the best performance.

    If ,while testing, you only want to check a few records you cans et "-ResultSetSize" to a small number and that is all that will be retuned.  This prevents you from having to run every record on every test to just work on adjust formats or tuning filters.

    HELP Get-AdUser -par result*


    ¯\_(ツ)_/¯

    Friday, December 19, 2014 6:13 PM