We help IT Professionals succeed at work.

Restore get-aduser functionality

IndwesAdmin
IndwesAdmin asked
on
123 Views
Last Modified: 2017-03-23
I have a script that has the following command:

$Users = Get-ADuser -Filter * -Properties * | `
      where { $_.whenCreated -ge $week }  | sort | select Name,WhenCreated,Description,EmailAddress

I have been successfully running this as a scheduled task on a Windows 7 box for quite awhile.  Then something changed and the script errors out without returning the list of users.  I have a similar, almost identical, script using get-adgroup which continues to work fine.

Has something changed or broken with the get-aduser command?

Thanks
Comment
Watch Question

Shaun VermaakSenior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Thanks ... wasn't even aware that v5 was available ... I will give it a try.

Author

Commented:
With v5 I get the same error shown below:
-----
Get-ADuser : The server has returned the following error: invalid enumeration context.
At D:\Program Files\SystemAdmin\PowerShell\_ERW_Reports\ERW-UsersLastWeek2.ps1:29 char:10
+ $Users = Get-ADuser -Filter * -Properties * | `
+          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-ADUser], ADException
    + FullyQualifiedErrorId : The server has returned the following error: invalid enumeration context.,Microsoft.ActiveDirectory.Management.Commands.GetADUser
 
0 new users in last 7 days
-----

The script is using the same loop used for the get-adgroup script.  Both scripts worked originally.  Now the get-adgroup script works but the get-aduser scripts errors out as shown above.
Senior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
That did it ... not sure why it worked for so long the way it was and then quit but am very glad to have the report back.  And I got updated to v5 in the process.  Win-Win.
Shaun VermaakSenior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019

Commented:
I guess your number of items is just at the point that this error is occurring with all these properties included

Author

Commented:
Thank a bunch Shaun!
Shaun VermaakSenior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019

Commented:
Glad we could help.
Please remember to endorse my, or any other expert's comments that you found helpful.