Hi All,
I am not a PS guru. I am a beginner in Powershell, so the question may be very basic. I am running the below powershell one-line script on our servers through a cron to fetch the list of ADUser objects. On the same server, I am also running seperate scripts to fetch ADComputer and ADDomainController objects too but on a different cron schedule. The scripts works on one set of servers but on few servers it gets timed out with "Invalid enumeration context" error. I read through some forums and I believe this error is because the numbers of objects retrieved is huge which makes the query to timeout. I am aware that this timeout value can be increased but do not want to do so.
Is there a way I can optimize this query using variables, so that it runs quickly.
script = Get-ADUser -Filter * -ResultSetSize $null -Properties AccountExpirationDate, accountExpires, badPasswordTime, Created, createTimeStamp, DisplayName, DistinguishedName, EmailAddress, Enabled, isDeleted, LastBadPasswordAttempt, lastLogon, LastLogonDate, lastLogonTimestamp, Modified, modifyTimeStamp, Name, PasswordExpired, PasswordLastSet, pwdLastSet, SamAccountName, SID, userAccountControl, UserPrincipalName, whenChanged, whenCreated | Select AccountExpirationDate, accountExpires, badPasswordTime, Created, createTimeStamp, DisplayName, DistinguishedName, EmailAddress, Enabled, isDeleted, LastBadPasswordAttempt, lastLogon, LastLogonDate, lastLogonTimestamp, Modified, modifyTimeStamp, Name, PasswordExpired, PasswordLastSet, pwdLastSet, SamAccountName, SID, userAccountControl, UserPrincipalName, whenChanged, whenCreated
Regards,
Vishnu.