1

I am trying to get the .Net version from the system and trying to check does my system have .Net version greater than or equal to 4.6 or not. Below is the code. From the code I am able to retrieve the release version. I am facing a problem in the if condition.

$myArray = @()

$myArray = @(Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse |
    Get-ItemProperty -Name Release,Release -EA 0 |
    Where { $_.PSChildName -match '^(?!S)\p{L}' } |
    Select Release)
Write-Output $myArray[0]
Write-Output $myArray[1]

$var1 = 393295
foreach ($var in $myArray) {
    Write-Output $var
    if ($var -ge $var1) {
        Write-Output same
    } else {
        Write-Output NOT same
    }
}

I am getting this error:

Cannot compare "@{Release=461808}" to "393295" because the objects are not the
same type or the object "@{Release=461808}" does not implement "IComparable".
At C:\Users\Desktop\DotNet.ps1:13 char:9
+     if ($var -ge $var1) {
+         ~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], ExtendedTypeSystemException
    + FullyQualifiedErrorId : PSObjectCompareTo
1
  • 1
    Select Release -> Select -ExpandProperty Release) you are comparing a object with a release property as supposed to just a string. note that $var could be a string so type it with [int] to make sure your math is working. Commented Jun 15, 2018 at 3:46

1 Answer 1

2

Change the foreach line as

foreach($var in $myArray.Release)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.