Skip to content

Instantly share code, notes, and snippets.

@tkouba
Created February 19, 2024 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkouba/c023aa272032b84efd43794717cc66ca to your computer and use it in GitHub Desktop.
Save tkouba/c023aa272032b84efd43794717cc66ca to your computer and use it in GitHub Desktop.
Get Kepware KEPServerEX V6 configuration root dirwectory.
<#PSScriptInfo
.VERSION 1.0
.GUID d1e5442a-c2cf-403d-a4f9-e4a54b4886bd
.AUTHOR Tomas Kouba
.COMPANYNAME Axians CZ
.COPYRIGHT (c) 2024 Axians CZ. All rights reserved.
.TAGS
.LICENSEURI
.PROJECTURI
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
#>
<#
.SYNOPSIS
Get KEPServerEX configuration root directory.
.DESCRIPTION
Get KEPServerEX configuration root directory. Relative path to KEPServerEX V6 configuration directory from root is '\Kepware\KEPServerEX\V6'
.INPUTS
NONE
.OUTPUTS
NONE
.EXAMPLE
C:\PS> .\Get-KepwareConfigRoot
Description
-----------
Get KEPServerEX configuration root directory.
.NOTES
Version : 1.0, 2024-02-19
Requires : PowerShell
.LINK
#>
[CmdletBinding()]
Param(
)
PROCESS {
#disable debug confirmation messages
if($PSBoundParameters['Debug']){$DebugPreference = "Continue"}
try {
# Relative path to KEPServerEX V6 configuration directory from root is
#$kepSubDir = '\Kepware\KEPServerEX\V6'
# Detect KEPServerEX configuration root from registry (running configuration)
if (-not $ConfigRoot) {
$regPath = 'HKLM:\SOFTWARE\Kepware\KEPServerEX\V6\Install', 'HKLM:\SOFTWARE\WOW6432Node\Kepware\KEPServerEX\V6\Install' | Where-Object { Test-Path -Path $_ }
if ($regPath) {
$ConfigRoot = (Get-ItemProperty -Path $regPath).AppDataPath
Write-Verbose "Set config root to default $ConfigRoot"
} else {
Write-Error "Kepware KEPServerEX registry entry not found."
break
}
}
return $ConfigRoot
}
catch {
#show error message (non terminating error so that the rest of the pipe input get processed)
Write-Error $_
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment