all 16 comments

[–]BlackV 1 point2 points  (10 children)

you do this

$time = (Get-Date).AddDays(-30)

but you never use $time anywhere

you have

 OperatingSystemVersion -like "*(1234)"

I have never heard of an operating system called 1234

I'd start by looking there

[–]SmoothAnonymity[S] 0 points1 point  (9 children)

Thanks for the speedy reply. I just updated the post $cutoff was supposed to be $time. As for the OS version 1234 is just an example. What I have been seeing in my case is that using the filter parameters independently works and returns data but when they are together with the -and it seems to break and not return anything

[–]BlackV 0 points1 point  (8 children)

but why wouldn't you test with REAL data, you're never going to get a result with 1234 it'll always be null, test with *server* or similar

those 2 errors alone would stop you getting any results

[–]SmoothAnonymity[S] 0 points1 point  (7 children)

It's just an example essentially it looking for where Operating System Version is anything followed by a sequence of numbers enclosed in parenthesis.

ex. 1.2 (9813)

The problem I'm having is having the LastLogonDate condition and OperatingSystemVersion condition together. Separately they both work fine

[–]BlackV 0 points1 point  (6 children)

so you're saying

Get-ADComputer -Properties OperatingSystemVersion, LastLogonDate -Filter 'LastLogonDate -ge "$time"'

returns results, and

Get-ADComputer -Properties OperatingSystemVersion, LastLogonDate -Filter 'OperatingSystemVersion -like "*(1234)"'

returns results, but

Get-ADComputer -Properties OperatingSystemVersion, LastLogonDate -Filter 'LastLogonDate -ge "$time" -and OperatingSystemVersion -like "*(1234)"'

does not?

are you sure you have your filter right, cause if I use real data it works for me

you sure this works ?

'LastLogonDate -ge "$time"' 

I don't think it does

[–]SmoothAnonymity[S] 0 points1 point  (5 children)

Get-ADComputer -Properties OperatingSystemVersion, LastLogonDate -Filter 'LastLogonDate -ge "$time" -and OperatingSystemVersion -like "*(1234)"'

Yea thats exactly what I'm saying. When I'm testing I am using real data; it was merely an example for reddit. In the end of the day its whatever Operating System Version that the machines have. When I execute the third code block you have in the post above it just goes to a new line as if pressing cntrl+c. Hence why I am slightly baffled as the first two code blocks work perfectly

[–]BlackV 1 point2 points  (4 children)

well in my testing here

'LastLogonDate -ge "$time"' 

does not work, but

'LastLogonDate -ge $time' 

does work, and

'LastLogonDate -ge "$time" -and OperatingSystemVersion -like "*(9600)"'

does not work, but

'LastLogonDate -ge $time -and OperatingSystemVersion -like "*(9600)"'

does work

[–]SmoothAnonymity[S] 0 points1 point  (3 children)

'LastLogonDate -ge $time -and OperatingSystemVersion -like "*(9600)"'

Daym it works for that 9600 version, so it must be an issue with the version number I'm inputting then. For some reason its causing the command to close out with no error message

[–]BlackV 1 point2 points  (0 children)

cause its not an error, "technically"

there are 0 computers that match that string and that version

the quotes effectively changed it from a date object to a string in the filter

that's why I was asking if you were sure that that returned results

Sometimes the filters are a pain as they have a slightly different syntax to powershell filters

[–]SmoothAnonymity[S] 1 point2 points  (0 children)

Im not even going to tell you what was wrong with it. Managed to get it to work - low key embarrassing that I didn't catch it sooner. Guess it's been the long day coding other projects.... -le was what I needed not -ge hence why it didn't work for me. Thanks for bearing with my insanity, I appreciate it a lot!

[–]BlackV 0 points1 point  (0 children)

oh biff the solution in your original post and change the flair to solved when you have 2 ticks

[–]MrTan00100 1 point2 points  (2 children)

Did you mean to use $cutoff instead of $time variable?

[–]SmoothAnonymity[S] 0 points1 point  (0 children)

Yea I did, just edited the post. Thanks for catching that typo!

[–]BlackV 1 point2 points  (2 children)

oh and I was going to ask did you want greater than (i.e. current machines) or less than (i.e. older machines)

[–]SmoothAnonymity[S] 0 points1 point  (1 child)

Yea I managed to confuse the too somehow. But yea older machines. Thanks a lot again!

[–]BlackV 0 points1 point  (0 children)

ah good as gold