Relevance: How to filter based on odd/even integer in a hostname string?

I’m trying to apply a fixlet only to computers with hostnames who’s 4th character from the end are an odd number. For example, our hostnames look like: “SOMECHARS1-AB”. Integer to the left of ‘-’ is what I’m attempting to filter on.

Currently I’m stuck at:

exists computer name whose (([something goes here] of it as integer) mod 2 = 1)

I’m unsure how to specify which character I want in [something goes here].

Can someone point me in the right direction?

Thanks!

Welcome to the community @tdl.

Does this work for you?

exists computer name whose ((first 1 of last 4 of it as integer) mod 2 = 1)

Using your computer name as a string to validate the detection (my computer name doesn’t match your critera)

Q: (first 1 of last 4 of "SOMECHARS3-AB" as integer) mod 2 = 1
A: True
T: 0.375 ms
I: singular boolean

EDIT: If you have computer with a name with a character that can’t be cast to an integer you will need to error trap

Q: (first 1 of last 4 of "ABCDEFG" as integer | 0) mod 2 = 1
A: False
T: 0.407 ms
I: singular boolean
2 Likes

That worked perfectly and makes sense. I knew I was getting close. Thanks!

1 Like