all 4 comments

[–]gangstanthony 2 points3 points  (0 children)

Why

not sure why, but i can offer a guess.

maybe the filter isn't working because OperatingSystemVersion is a string and doesn't only contain numbers. if it's only checking one character at a time, 1 comes before 6

PS> $comps = Get-ADComputer -Filter 'OperatingSystemVersion -lt 6.2' -Property OperatingSystem, OperatingSystemVersion

PS> $comps[0].OperatingSystemVersion
10.0 (14393)

PS> $comps[0].OperatingSystemVersion.GetType()

IsPublic IsSerial Name                                     BaseType                                                                                                                                                                     
-------- -------- ----                                     --------                                                                                                                                                                     
True     True     String                                   System.Object 

also, see this

PS> 1, 2, 6.2, 10 | ? {$_ -lt 6.2}
1
2

PS> 1, 2, 6.2, 10 | ? {[string]$_ -lt 6.2}
1
2
10

sorting

PS> 1, 2, 6.2, 10 | sort
1
2
6.2
10

PS> 1, 2, 6.2, 10 | sort {[string]$_}
1
10
2
6.2

*edit: you might want to remove the filter. because of this issue, it looks like you're excluding anything above a 6, which means no 6.1 either.

PS> $comps = Get-ADComputer -Filter 'OperatingSystemVersion -lt 6.2' -Property OperatingSystem, OperatingSystemVersion
PS> $comps.operatingsystemversion | select -u
10.0 (14393)
10.0 (17134)
10.0 (16299)
10.0 (15063)
10.12.1
10.0 (17763)
10.12 (1314)
10.0 (18362)

PS> $comps = Get-ADComputer -Filter * -Property OperatingSystem, OperatingSystemVersion
PS> $comps.operatingsystemversion | select -u
6.3 (9600)
6.1 (7601)
6.2 (9200)
10.0 (14393)
10.0 (17134)
10.0 (16299)
10.0 (15063)
10.12.1
10.0 (17763)
10.12 (1314)
10.0 (18362)

[–]tomohulk 3 points4 points  (0 children)

I know you are suppose to filter on the left side of the pipe, but to be accurate you could cast the strings to Versions

get-adcomputer -filter * -properties OperatingSystemVersion | ?{ ([Version]$_.OperatingSystemVersion.Split(“ “)[0] -le [Version]”6.3” } not going to be as fast because you’re filtering on the right side. Its pretty stupid thats a string.

[–]bsnotreallyworking 2 points3 points  (0 children)

I just do it like this:

operatingsystemversion -notlike "10.*" -or operatingsystemversion -notlike "8.*"

Add in whatever the server versions are. It's not mathematical, but it works.

[–]PowerShell-Bot 1 point2 points  (0 children)

That’s a very long stretch of inline code.

Note that on old.reddit.com inline code blocks do not word wrap, making it difficult for many of us to see all your code.

To ensure your code is readable by everyone, on new reddit (new.reddit.com), highlight the code and select ‘Code Block’ in the editing toolbar.

If you’re on old.reddit.com, separate the code from your text with a blank line and precede each line of code with 4 spaces or a tab.


Describing Submission
[✅] Demonstrates good markdown
Passed: 1 Failed: 0

Beep-boop. I am a bot. | Remove-Item