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.
-likeor-matchif you want to use wildcards.