0

I require a AD powershell one liner that will return all active computers (lastlogonate > 30 days).

$inactive = (Get-Date).AddDays(-30)
 
Get-ADComputer -filter {lastlogondate -gt $inactive }

I can do the above but I ideally need a one liner to include in a framework that executes a list of queries. I thought the below would work:

Get-ADComputer -filter {lastlogondate -gt $(Get-Date).AddDays(-30) }

But I get an error "...value of argument "path" is not valid"

1 Answer 1

1

Replace the curly braces with quotes...

Get-ADComputer -filter "lastlogondate -gt '$((Get-Date).AddDays(-30))'" 
Sign up to request clarification or add additional context in comments.

2 Comments

sorry, marked as answered too early. the query parses but returns no results. the query took a long time to return the result as our estate is large so i thought it was working
works in my env for sure... and show results, did you changed anything?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.