SOLVED

Get-aduser is not working in PS7 if i am trying to filter user using attribute Whencreated.

Copper Contributor

below code is working in PS 5.1 but Not in PS 7.4.2

 

$when = $(Get-Date).AddDays(-3).date
$data = Get-ADUser -Filter {whenCreated -ge $When}
$data.count

 

Error: Get-ADObject: Error parsing query: 'whenChanged -gt 05/06/2024 00:00:00' Error Message: 'Operator Not supported: ' at position: '19'.

5 Replies
You should not be using the Azure AD module, switch to the Graph SDK instead:

Get-MgUser -Filter "createdDateTime ge $([datetime]::UtcNow.AddDays(-3).ToString("s"))Z" -All:$true
best response confirmed by Imadnazim (Copper Contributor)
Solution

@Vasil Michev 

 

Hi, Vasil.

 

This is in relation to the on-premise ActiveDirectory module, not any Azure modules.

 

@Imadnazim 

 

Your post is somewhat confusing since your example uses "-ge" yet the error reports "-gt". Even so, I've tried both under PowerShell 7.4.2 and cannot reproduce the issue.

 

Can you please check your example in this post is accurate?

 

LainRobertson_1-1715296436826.png

 

Also, check both the module and (optionally) the command to ensure it's not coming from an alternate installation.

 

Verifying commandlet(s):

LainRobertson_3-1715296789696.png

 

Verifying modules(s):

LainRobertson_2-1715296667906.png

 

Cheers,

Lain

Hello @LainRobertson ,

 

I ran commands as suggested by you. My AD module is different that could be an issue here.

 

Imadnazim_0-1715325623567.png

 

 

@Imadnazim 

 

Hi, Imad.

 

That path suggests the ActiveDirectory module you're seeing may be being imported as a remote session, which may explain the shown error - which is different again to the two previous errors.

 

What do you see if you run the command below?

 

LainRobertson_0-1715326833253.png

 

If you see the a module with a path like the one above beginning with C:\Windows\system32\WindowsPowerShell, then that's the module you want to make use of, not the one from your screenshot.

 

Cheers,

Lain

 

1 best response

Accepted Solutions
best response confirmed by Imadnazim (Copper Contributor)
Solution

@Vasil Michev 

 

Hi, Vasil.

 

This is in relation to the on-premise ActiveDirectory module, not any Azure modules.

 

@Imadnazim 

 

Your post is somewhat confusing since your example uses "-ge" yet the error reports "-gt". Even so, I've tried both under PowerShell 7.4.2 and cannot reproduce the issue.

 

Can you please check your example in this post is accurate?

 

LainRobertson_1-1715296436826.png

 

Also, check both the module and (optionally) the command to ensure it's not coming from an alternate installation.

 

Verifying commandlet(s):

LainRobertson_3-1715296789696.png

 

Verifying modules(s):

LainRobertson_2-1715296667906.png

 

Cheers,

Lain

View solution in original post