Reputation: 3
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.).
Upvotes: 0
Views: 160
Reputation: 26170
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.
Upvotes: 3