0

I'm trying to get multiple filters to work getting a list of users' computers. My conditions are:

  • have logged in within the last 30 days
  • excluding any server operating
  • systems excluding servers that start with "Rose"
  • aren't disabled

It seems to work filtering out everything except the computer names that start with "Rose". The format is the same for all conditions. The $time has a get-date.adddays(-30) already loaded. Here's my 1-liner:

Get-adcomputer -filter "OperatingSystem -notlike '*server*'" -properties * |Where-Object {$_.LastLogonDate -gt $time -and ($_.Enabled -eq $true) -and ($_.name -ne 'Rose*')} |select name,lastlogondate,PrimaryGroup |Export-Csv C:\Users.csv

I tried to load the -filter property with my conditions but I couldn't get more than 1 filter to work, so I moved them to the where-object section.

3
  • 2
    You need to use -like or -match if you want to use wildcards. Commented Aug 12, 2020 at 19:35
  • I needed to use -notlike but yeah, that was the issue. Thanks! Make that a reply and not a comment so I can mark it as the answer. Commented Aug 12, 2020 at 22:15
  • 1
    Oh, yes you are correct ^^ glad I could help Commented Aug 12, 2020 at 22:34

1 Answer 1

1

The operator -ne does not support wildcards. From the about_operators help page:

The comparison operators also include operators that find or replace patterns in text. The (-match, -notmatch, -replace) operators use regular expressions, and (-like, -notlike) use wildcards *.

You should be able to use -notlike or -notmatch instead.

Sign up to request clarification or add additional context in comments.

Comments

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.