Jerome Lefebvre

Updating PI SMT's list of hidden plugin

Blog Post created by Jerome Lefebvre on Jan 18, 2019

By default PI SMT has many plugins, and by default they are all shown in PI SMT.

It always makes my eyes water when I have to scroll through the long list of plugin that I never open, thus I try to prune the list as much as I can.

I believe this is good practice for anybody who wants to make a PI a tiny bit easier to administrate. (Don't have AF Link installed? Remove the plugin that manages it!)

 

I also have a lot of machines that I have SMT installed, thus I need to go through this setting screen a lot.

Thus, I wanted to automate this procedure. I couldn't find any APIs to manually update this setting, thus I decided to go directly editing the XML file.

The PowerShell script below is what I came up with. To use it, you set the variables you want to hide from PI SMT to true.

**THE SCRIPT BELOW IS NOT INTENDED FOR PRODUCTION USE, SIMPLY MEANT AS A PERSONAL PROJECTS **

 

<#
Usage, this script has to run as an administrator
#>


$Settings = @{
"AF Link" = $true
"Alarm Groups" = $true
"Archive Editor" = $false
"Archives" = $false
"AutoPointSync List" = $true
"Backups" = $false
"Batch Custom Names" = $true
"Batch Database" = $true
"Batch Generator" = $true
"Current Values" = $false
"Database Security" = $false
"Digital States" = $false
"Firewall" = $true
"Identities, Users, &amp; Groups" = $false
"Interface List" = $true
"Licensing" = $false
"Mappings &amp; Trusts" = $false
"Message Logs" = $false
"Module Database" = $true
"Network Manager Statistics" = $false
"Performance Counters" = $true
"Performance Equations" = $true
"PI Services" = $true
"PI Version" = $true
"Ping" = $true
"Point Builder" = $false
"Point Classes" = $true
"Point Source Table" = $true
"Reason Tree" = $true
"Security Settings" = $true
"Snapshot and Archive Statistics" = $false
"SNMP" = $true
"SQC Alarms" = $true
"Stale and Bad Points" = $true
"TCPResponse" = $true
"Totalizers" = $true
"Tuning Parameters" = $false
"Update Manager" = $true
}


$PluginsToHide = $Settings.Keys | Where {$Settings[$_]}
$line = $PluginsToHide -join "|"


function updateSMTSettingFile {
param([String]$filePath, [String]$newSetting)
$xpath = "/configuration/userSettings/SMTHost.My.MySettings/setting[16]/value"
$xml = [xml](Get-Content $filePath)
$xml.SelectNodes($xpath) | % {
$_.InnerXml = $line
}
$xml.Save($filePath)
}


$smt = Get-Process SMTHost -ErrorAction SilentlyContinue


if ($smt) {
# try gracefully first
$smt.CloseMainWindow()
Sleep -Seconds 1
if (!$smt.HasExited) {
Write-Host "Couldn't shutdown PI SMT"
exit
# If we want to force quit, we can by using: $smt| Stop-Process -Force
}
}


# Global setting file
$globalSettingPath = $env:PIHOME + "\smt3\SMTHost.exe.config"
updateSMTSettingFile -filePath $globalSettingPath -newSetting $line


# Current user setting file
$smtVersion = (Get-ItemProperty HKLM:\Software\WOW6432Node\PISystem\SMT3 | select CurrentVersion).CurrentVersion
$smtVersionWithMinorStrip = $version.Substring(0, $version.lastIndexOf('.')) + ".0"
$localSettingPath = $env:USERPROFILE + "\AppData\Local\OSIsoft\SMTHost.exe_StrongName_ebdkvkyxoz4e1ufktoicytfbtyr5hril\" + $smtVersionWithMinorStrip + "\user.config"
updateSMTSettingFile -filePath $localSettingPath -newSetting $line


#Start SMT if it was already opened.
if ($smt) {
$pathToSMT = $env:PIHOME + "\SMT3\SMTHost.exe"
Start-Process $pathToSMT
}


Outcomes