Powershell IF's
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
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
Answers (2)
Please log in to answer
Posted by:
djordan
7 years ago
#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.
Posted by:
rad33k
7 years ago
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:
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
}
Comments: