RJKSolutions

PISrvStart and PISrvStop

Discussion created by RJKSolutions on Feb 11, 2013
Latest reply on Feb 13, 2013 by matzen

Decided that for fun we should re-write the PI Server start and stop command files in to PowerShell scripts, and make some added logging improvements.  In fact, I have a longer term goal to have the PI Server start up script kick off some other remote PS scripts but that is a story for another day.

 

Have OSIsoft already looked at moving over to PS instead of command files?

 

Example (from PISrvStart.bat):

 
@rem PLI 23001. The GetAdmPath function was not working on every operating system.
:GetAdmPath
   @set AdmPath=%PIServer%adm
   @if EXIST "%AdmPath%\pidiag.exe" @GOTO :EOF
   @set AdmPath=%CD%
   @if EXIST "%AdmPath%\pidiag.exe" @GOTO :EOF
   @for /F "skip=2 tokens=1 delims=:" %%i in ('reg query HKLM\SOFTWARE\PISystem\PI /v InstallationPath') do @set PIDrive=%%i
   @set PIDrive=%PIDrive:~-1%
   @for /F "skip=2 tokens=2 delims=:" %%i in ('reg query HKLM\SOFTWARE\PISystem\PI /v InstallationPath') do @set AdmPath=%PIDrive%:%%i\adm
   @goto :eof

 

 

becomes

 
Function GetAdmPath
{
     try
     {
          $admpath = $Env:PISERVER
          if (!$admpath.EndsWith("\")) { $admpath += "\" }
          $admpath += "adm"
          
          if (Test-Path -Path ($admpath + "\pidiag.exe"))
          {
               return $admpath
          }
     }
     catch [System.Exception]
     {
          try
          {
               $admpath = (Get-ItemProperty -Path "HKLM:\Software\PISystem\PI").InstallationPath
               if (!$admpath.EndsWith("\")) { $admpath += "\" }
               $admpath += "adm"
               
               if (Test-Path -Path ($admpath + "\pidiag.exe"))
               {
                    return $admpath
               }
          }
          catch [System.Exception]
          {
               return $null 
          }
     }
}

 

Outcomes