Uncomprehensive error with Get-ADUser

Hi all,

I’m coming here to find a solution to a simple command not working with Get-ADUser.
I type in a PS admin box this command:
Get-ADUser -Filter {Enabled -eq $true -and LastLogonTimeStamp -lt $((Get-Date).AddDays(-90).ToFileTime())} -Server MyDCServer.com

And I get the following error:
Cannot process argument because the value of argument “path” is not valid. Change the value of the “path” argument and run the operation again.

What am I doing wrong?

Thanks,
Olivier

Hi there and welcome!

For future posts, please format your code: How to format code on PowerShell.org

Try

$Date = (Get-Date).AddDays(-90).ToFileTime()
Get-ADUser -Filter {Enabled -eq $true -and LastLogonTimeStamp -lt $Date}

If you need the add the server bit back in you can. Not 100%, but I don’t think the ToFileTime method is needed here but I haven’t tested it, so I left it.