/build/static/layout/Breadcrumb_cap_w.png

Powershell Script to look at old OS versions doesn't pick up Windows 8 computers only Windows 10

Hi all,

I'm using the following powershell script to try and export everything older than Windows 10 version 1803 so we can keep pc's up to date. It picks up everything that is Windows 10 and not on version 1803 yet. For some reason, it doesn't pick up a number of pc's that are Windows 7 or Windows 8 when the version number is below 10.0 (17134). I can't understand why this would be the case. Can anyone explain to me why, please? Strange thing is, if I change the '-lt' to '-gt', I get all the ones who have updated on the preview release installed which makes sense, but now the Windows 7 and Windows 8 are showing here with the greater than symbol. WHY? *facepalm*


Get-ADComputer -Filter {OperatingSystemVersion -lt "10.0 (17134)"} -Property * | Select-Object Name,OperatingSystem,OperatingSystemVersion | Sort-Object -Property Name | Export-Csv -path "C:\Version.csv" -NoTypeInformation


2 Comments   [ + ] Show comments
  • could be the windows 7-8 do not have the proper plugin or commandlets. Have you tried running this on a windows 7 and windows 8 machines via the powershell command prompt to see what errors it kicks? - SMal.tmcc 6 years ago
  • PowerShell is doing the comparison as strings ("10.0 (17134)" isn't a number), so it only needs to check the first character to determine 1 is less than 7 or 8. I think you'd need to change the -lt to -ne, although then the list would include 1809. - PaulGibson 6 years ago

Answers (2)

Posted by: rad33k 6 years ago
Fourth Degree Brown Belt
2

Hi,

I believe it is most likely caused by the "Version" format you are trying to compare - "10.0 (17134)" is not a valid version.
If you try to convert it to [version] type, you would see following PS error:
Cannot convert value "10.0 (17134)" to type "System.Version". Error: "Input string was not in a correct format."

In this way you are performing a 'string' comparison which simply makes no sense. You can test it wit the following code:

$TMP = "10.0 (17134)"
$TMP2 = "6.1"
$RES = $TMP -lt $TMP2
Write-Host "`$TMP=$TMP`n`$TMP2=$TMP2`nOperation:`t$TMP < $TMP2`nResult:`t`t$RES"


Here are my results ;)

Operation:	10.0 (17134) < 6.1
Result: True

Operation: 10.0 (17134) < 7.0
Result: True

Operation: 10.0 (17134) < 80.0
Result: True

Operation: 10.0 (17134) < 123456
Result: True

Operation: 10.0 (17134) < 000.00 (00000)
Result: False

Operation: 10.0 (17134) < a
Result: True

Operation: 10.0 (17134) < dummy text bla bla
Result: True


I would suggest to export all the values from the environment and then think of a valid comparison method (split or regular expression may help to achieve the goal).
You can put here some of the values, maybe we could suggest something more.
Cheers.

Posted by: SMal.tmcc 6 years ago
Red Belt
1

You can also use WMIC to get this all well MS provided built-in sysinfo and ver commands.


wmic os where "not version='10.0.17134'" get version

systeminfo | findstr /B /C:"OS Version"

ver



Comments:
  • this one works just fine - Channeler 6 years ago
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ