All the other build "numbers" as composed of digits. You need to make 20H2 a string.
"10.0 (19042)" { "20H2" }
You did that when you compared $Result -eq '20H2'.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have this script I've used to get windows versions on our domain computers, and it has always worked perfectly. I've just updated it to find computers that have installed Windows 10 19042 20H2. But now I get nothing but errors. My thought is the H in the version number is possibly causing this problem, but then I'm dumb and can't be trusted with my suspicions. Any thoughts on the matter are very much appreciated. I'll include the code with domain information redacted.
$List = Get-ADComputer -SearchBase "ou=<REDACTED>,dc=<REDACTED>,dc=com" -filter {enabled -eq $true} -properties OperatingSystemVersion
foreach ($System in $List) {
$Result = switch ($System.OperatingSystemVersion){
"10.0 (10240)" {1507}
"10.0 (10586)" {1511}
"10.0 (14393)" {1607}
"10.0 (15063)" {1703}
"10.0 (16299)" {1709}
"10.0 (17134)" {1803}
"10.0 (17763)" {1809}
"10.0 (18362)" {1903}
"10.0 (18363)" {1909}
"10.0 (19041)" {2004}
"10.0 (19042)" {20H2}
}
set n=0
if ($Result -eq '20H2') {
echo $System.Name >> c:\apps\20H2_mo_windows_versions.txt
echo $System.OperatingSystemVersion >> c:\apps\20H2_mo_windows_versions.txt;
echo $Result >> c:\apps\20H2_mo_windows_versions.txt
echo _____________________ >> c:\apps\20H2_mo_windows_versions.txt
set /a n=%n%+1
}
}
All the other build "numbers" as composed of digits. You need to make 20H2 a string.
"10.0 (19042)" { "20H2" }
You did that when you compared $Result -eq '20H2'.
I don't think this line of code:
set n=0
...does what you think it does. With default aliases in PowerShell, this will set a variable named n=0 with an empty (null) value.
Also you have this:
set /a n=%n%+1
That's not going to work in PowerShell either. PowerShell doesn't use % delimiters for environment variables, and the set command is by default aliased to the Set-Variable cmdlet.
If you goal is to set a PowerShell variable to 0 and increment it, you need these lines instead:
$n = 0
and
$n++
And here is the error:
In the error, the "20H2" is what is underlined as the offending bit of code, in case the formatting is off in my reply. Here it is (again, with company identifying information redacted):
20H2 : The term '20H2' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At C:\<REDACTED>\Desktop\My Scripts\PowerShell\windows version\20H2\MO_windows_version.ps1:15 char:23