RJKSolutions

How to automate OSIsoft package installations - the beginning of the journey

Discussion created by RJKSolutions on Nov 14, 2013

Let's take a small stroll down the winding path of Managed PI. In an ideal world we (I'm putting you all in the same bracket as my own thoughts) would like to live in a world where for systems or environments we know well and trust, that we could safely throw an OSIsoft software package at it along with a PowerShell script and have the package installed gracefully even without us knowing or needing to do ANYTHING. I've somewhat done this for some projects but as with almost all code I write it feels outdated & inefficient as soon as I've written the first line. I must continually improve! Anyway...I've pulled out some code on how you can start to approach such a conundrum using PowerShell. Thing is it actually works, and works well. The code I've pulled out is not clean nor beautiful so it will evolve quickly over the iterations on this thread, be sure to subscribe to the forum.

 

Here is the code, let's call it v0.1:

 

 

 
# Some variables
$package = "C:\PIAFClient_2012_SP1_.exe"
$newTemp = "C:\MyTempPath\"
$origTemp = $Env:TEMP 
 
# Control temp directory
[environment]::SetEnvironmentVariable("Temp",$newTemp,"User")
[environment]::SetEnvironmentVariable("Temp",$newTemp,"Machine")
[environment]::SetEnvironmentVariable("Temp",$newTemp,"Process")
 
# Extract
Start-Process -FilePath $package -ArgumentList "-nr -y" -Wait
 
# Activate silent installation - you could just pass silent.ini as an argument.
Rename-Item ($newTemp + "AFClient_2.5.1.5159\setup.ini") -NewName "old-setup.ini"
Rename-Item ($newTemp + "AFClient_2.5.1.5159\silent.ini") -NewName "setup.ini"
 
# Replace server defaults
(Get-Content ($newTemp + "AFClient_2.5.1.5159\setup.ini")) | ForEach-Object { $_ -replace "PI_SERVER=MyServer", "PI_SERVER=RHYSPI" } | Set-Content ($newTemp + "AFClient_2.5.1.5159\setup.ini")
# ... some other defaults replaced, omitted for shortness of post
 
# Start installation - should check the extraction has worked but assume it has
Start-Process ($newTemp + "AFClient_2.5.1.5159\setup.exe") -ArgumentList ($newTemp + "AFClient_2.5.1.5159\setup.ini") -Wait
 
# Validate installation
# Hardcoded paths; I know I should use the registry to find the paths.
if ((Test-Path "C:\Program Files (x86)\PIPC\AF\PublicAssemblies\OSIsoft.AFSDK.dll") -eq $true)
{
    [String] $ver = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\Program Files (x86)\PIPC\AF\PublicAssemblies\OSIsoft.AFSDK.dll").FileVersion
    if ($ver -eq "2.5.1.5159")
    {
        # Seems to have worked so grab a beer, in fact grab 2.
    }
}
 
[environment]::SetEnvironmentVariable("Temp",$origTemp,"User")
[environment]::SetEnvironmentVariable("Temp",$origTemp,"Machine")
[environment]::SetEnvironmentVariable("Temp",$origTemp,"Process")

 I'll sneak off to my man cave now and work on v0.2...

 

 

Outcomes