Command line Service PSU with alternative config folder

While checking the settings documentation page
i found it’s possible to have an alternative appsettings.json file that could have section that overide the main file. :slight_smile:

unfortunately it’s set in “$Env:ProgramData\PowerShellUniversal”

question is it possible something in the comand line, and the service command line to set on another folder?

example:
New-Service -Name “PowerShellUniversal” -BinaryPathName “Universal.Server.exe --service --configpath d:\PoshUniversalProgData” -Description “PowerShell Universal server service.” -DisplayName “PowerShell Universal” -StartupType Automatic

thanks.

Product: PowerShell Universal
Version: 1.5.2

We can add that setting. It doesn’t exist right now. I will add it to our backlog.

If there are certain settings you want to override without creating a totally different config file, you can also use environment variables.

For example:

If you wanted to set the AppInsights key.

  "ApplicationInsights": {
    "InstrumentationKey": ""
  },

You would set the environment variable (there are 2 underscores between sections):

$Env:ApplicationInsights__InsturmentationKey = "xyz"
1 Like

my purpose was more proposing a way to easily switch version of Powershell universal when putting e service mode.

but if the variable is ok, we can set in the service env.
that allow me to stop the service just rename the powershelluniversal app folder unzip the new one restart and see if all is ok. if any issue occurs i can switch back from the old folder

will try that below line (i use this kind of line on influxdb telegraf service environment the “\0” allow the reg_multi_string to have multiple line

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PowerShellUniversal" /v Environment /t REG_MULTI_SZ /d Kestrel__Endpoints__HTTP__Url="http://*:80"\0Logging__Path="d:/POSHU_data/log.txt"\0Data__RepositoryPath="d:\\POSHU_data\\UniversalAutomation\\Repository"\0Data__ConnectionString="d:\\POSHU_data\\UniversalAutomation\\database.db"\0UniversalDashboard__AssetsFolder="%ProgramData%\\PowerShellUniversal\\Dashboard" /f

ok so the easier way to set the environement variable in full powershell:

$EnvValueREGMultiSZ = @()
$EnvValueREGMultiSZ += "Logging__Path=C:/Workspace/PowershellUniversall/appdata2/log.txt"
$EnvValueREGMultiSZ += "Data__RepositoryPath=C:\\Workspace\\PowershellUniversall\\appdata2\\Repository"
$EnvValueREGMultiSZ += "Kestrel__Endpoints__HTTP__Url=http://*:5000"
   
   
#install the service
New-Service -Name "PowerShellUniversal" -BinaryPathName "C:\Workspace\PowershellUniversall\Universal.1.5.2\Universal.Server.exe --service" -Description "PowerShell Universal server service." -DisplayName "PowerShell Universal" -StartupType Manual
   
    $newServiceConfig = @{
    Path		= "HLM:\SYSTEM\CurrentControlSet\Services\PowershellUniversal"
    Name		= "Environement"
    Type		= "MultiString"
    Value	=$EnvValueREGMultiSZ
}
   
New-ItemProperty @$newServiceConfig

Tonic8