Restore get-aduser functionality

IndwesAdmin
IndwesAdmin used Ask the Experts™
on
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

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018
Commented:
Upgrade your Powershell to v5+

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.
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Technical Specialist
Awarded 2017
Distinguished Expert 2018
Commented:
Please try
$Users = Get-ADuser -Filter * -Properties whenCreated,Description,EmailAddress | where { $_.whenCreated -ge $week }  | sort | select Name, WhenCreated, Description, EmailAddress

Open in new window

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 VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

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 VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial