/bundles/itninjaweb/img/Breadcrumb_cap_w.png
Morning,

I am working on a script to install an in house application. One Pre Req is .Net. I need my script to check if the version exists. I have set this up but how do I say if the value is false run setup.exe

        $val = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" -Name "Version"
        if ($val.Version -ne 4.6.000.81)
        {
        Start-Process "\\Share\rollout\Installations\Scripts\Files\Confirm\NDP46-KB3045557-x86-x64-AllOS-ENU.exe" /s
        }

On this part -   if ($val.Version -ne 4.6.000.81) I would like a if this is false run the below kind of thing, Any help is appreciated. 
0 Comments   [ + ] Show comments

Comments


All Answers

0

#Checks and Installs .Net 4.6.1
        $val = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" -Name "Version"
        if ($val.Version -ne 4.6.000.81 -eq $True)
        {
        Start-Process "\\Share\rollout\Installations\Scripts\Files\Confirm\NDP46-KB3045557-x86-x64-AllOS-ENU.exe" /s
        }


Worked it out.
Answered 08/10/2017 by: djordan
Senior White Belt

0
Does it really works now?
I checked above code with few values and it always returned TRUE for me.

I would suggest to use a quotes for version value that you are comparing to and also consider [version] type, as then you can use other comparison operators like -lt -gt etc.
I mean something like this:
    #Checks and Installs .Net 4.6.1
$val = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" -Name "Version"
$val2 = "4.6.000.81"

if ([version]$val.Version -lt [version]$val2)
{
    Start-Process "\\Share\rollout\Installations\Scripts\Files\Confirm\NDP46-KB3045557-x86-x64-AllOS-ENU.exe" /s
}
Answered 08/10/2017 by: rad33k
Fourth Degree Green Belt

  • Hi, Thanks for the suggestion. Yes it was working when I tested but yours appears more bullet proof, Quite new to using powershell ha. Thanks!
  • You might possibly be able to answer my other question.

    http://www.itninja.com/question/vcreds-powershell