0

How would you simplify the following script?

Get-ADComputer -Filter * -properties * | Where-Object {
  $_.OperatingSystem -like "*2003*" -and
  $_.OperatingSystem -like "*2008*" -and
  $_.OperatingSystem -like "*2012*"
} | sort name | ft name, description, OperatingSystem

I've been looking for a while on this one and would like some help. I know I could simplify by using "*20*" and I will get my result but I'd like to know how to use multiple criteria (i.e. XP, Windows 10, etc.).

2
  • 2
    Maybe a quibble, but what you have there is never going to return anything as long as those conditions are ANDed instead of ORed. Commented Jan 5, 2016 at 11:34
  • how about actually using tat -Filter thingie for a start? Commented Jan 5, 2016 at 11:37

1 Answer 1

3

you could use -match operator with a regex pattern

...|?{$_.operatingsystem -match "2008|2012|XP" }

Know that ? is an alias for Where-Object. See the output of Get-Alias for more of these.

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

1 Comment

I was looking for the acknowledgement. Done

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.