Pages

Tuesday, 13 November 2018

IF Version AND Service

The following PowerShell code was used to run the updater for a specific version of E-Prime where its 'hasplms' Service had stopped running. By querying the .exe file in the installation folder it was possible to find the product version which could then be compared against.

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
#Create a variable of the path to the file
$EPrimePath = "$envProgramFilesX86\PST\E-Prime 2.0\Program\E-Studio.exe"
    
#If the file exists 
If (Test-Path -Path $EPrimePath) {

       #Create a variable of the 'ProductVersionRaw' attribute, as 'ProductVersion' on its own contains commas and spaces in this instance

       $EPrimeVersion = (Get-Item -Path $EPrimePath).VersionInfo.ProductVersionRaw

       #Compares the above .exe version AND that no 'hasplms' Service is running
       #The '-ErrorAction' is used to continue running the script if the Service is missing (otherwise it would error)

       If (($EPrimeVersion -eq '2.0.10.356') -And (-Not(Get-Service 'hasplms' -ErrorAction SilentlyContinue))) {
           
           #Run the .exe file with E-Prime specific parameters
           Execute-Process -Path "$dirFiles\haspdinst.exe" -Parameters '-i -fi -kp -v -nomsg'
       }
}

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

Download IF Version AND Service.ps1

No comments:

Post a comment