Hi, I’m trying to get this script sorted out but I’m having an issue. No matter what I put for the fileversion to check for it always comes back as “Already Installed”. So if I change the ‘14.2.770.0’ to another value it should come back as “Not Installed”. Any ideas?
function CheckSepVersion
{
$computername = $env:COMPUTERNAME
$OSArch = Get-WmiObject -Class win32_OperatingSystem -ComputerName $computername | select pscomputername, OSArchitecture
if ($OSArch.OSArchitecture -eq “64-bit”)
{
(Get-Item “C:\Program Files (x86)\Symantec\Symantec Endpoint Protection\smc.exe”).VersionInfo.FileVersion
}
else
{
(Get-Item “C:\Program Files\Symantec\Symantec Endpoint Protection\smc.exe”).VersionInfo.FileVersion
}
}
if (CheckSepVersion -eq ‘14.2.770.0’)
{
Write-Output “Already installed”
}
else
{
Write-Output “Not installed”
}
Olaf
August 21, 2018, 9:18am
2
Let’s tweak your code a little bit … (BTW: you should put it between the tags, not after them! )
function Get-SepVersion{
$computername = $env:COMPUTERNAME
$OSArch = Get-WmiObject -Class win32_OperatingSystem -ComputerName $computername | Select-Object -Property pscomputername, OSArchitecture
if ($OSArch.OSArchitecture -eq “64-bit”){
version .VersionInfo.FileVersion
}
else {
version .VersionInfo.FileVersion
}
}
if (Get-SepVersion -eq [version]‘14.2.770.0’) {
Write-Output “Already installed”
}
else{
Write-Output “Not installed”
}
If you like to compare versions you should cast the numbers as version objects.
js2010
August 21, 2018, 9:18am
3
Weird. 14 invisible characters at the end?? I guess you can trim it.
PS C:\Users\js\Downloads> $a = (get-item VSCodeSetup-x64-1.19.2.exe).VersionInfo.fileversion
PS C:\Users\js\Downloads> $a
1.19.2
PS C:\Users\js\Downloads> $a.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
PS C:\Users\js\Downloads> $a -eq '1.19.2'
False
PS C:\Users\js\Downloads> $a -match '1.19.2'
True
PS C:\Users\js\Downloads> $a -match '1.19.2$'
False
PS C:\Users\js\Downloads> $a -match '^1.19.2'
True
PS C:\Users\js\Downloads> $a | measure -Character
Lines Words Characters Property
----- ----- ---------- --------
20
PS C:\Users\js\Downloads> '1.19.2' | measure -Character
Lines Words Characters Property
----- ----- ---------- --------
6
PS C:\Users\js\Downloads> $a.trim() -eq '1.19.2'
True
PS C:\Users\js\Downloads> "...$a..."
...1.19.2 ...