KB0053 - Refreshing specific configuration files manually

KB0053 - Refreshing specific configuration files manually

Product Versions

- PowerShell Universal 3.x
- PowerShell Universal 4.0.x
- PowerShell Universal 4.1.x

Purpose

When making changes in PowerShell Universal, the configuration system will detect changes to files through the management API, admin console and on disk. In certain circumstances, it may be necessary to disable the local file system watcher. When this is done, changes made on disk will not automatically reload. This document outlines code that can be used to manually refresh a configuration file. 

PowerShell Universal v4.2 and later have APIs available to do this directly.

Workaround

Within a script, API or dashboard running within the Integrated environment, you can access the internal services of PowerShell Universal to allow for reloading specific configuration files. This example reloads dashboards. 
  1. $ConfigService = $UniversalClient.GetType().GetProperty("_configService", [System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::NonPublic).GetValue($UniversalClient)
  2. $SyncAsync = $ConfigService.GetType().GetMethod("SyncAsync", [Type[]]@())
  3. $Method = $SyncAsync.MakeGenericMethod([PowerShellUniversal.Dashboard])
  4. $Method.Invoke($ConfigService$null).GetAwaiter().GetResult()
To reload variables, you could use the following. 
  1. $ConfigService = $UniversalClient.GetType().GetProperty("_configService", [System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::NonPublic).GetValue($UniversalClient)
  2. $SyncAsync = $ConfigService.GetType().GetMethod("SyncAsync", [Type[]]@())
  3. $Method = $SyncAsync.MakeGenericMethod([PowerShellUniversal.Variable])
  4. $Method.Invoke($ConfigService$null).GetAwaiter().GetResult()
In PowerShell Universal v4.x and later, you can take advantage of new features of PowerShell 7.3 to simplify these calls. 
  1. $ConfigService = $UniversalClient.GetType().GetProperty("_configService", [System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::NonPublic).GetValue($UniversalClient)
  2. $ConfigService.SyncAsync[PowerShellUniversal.Variable]().GetAwaiter().GetResult()

    • Related Articles

    • KB0020 - Firewall Configuration for PowerShell Universal

      Purpose The purpose of this document is to provide information about the necessary filewall settings required by PowerShell Universal. Overview PowerShell Universal does not offer a built in firewall. We recommend using standard firewalls available ...
    • KB0001 - PSU Uninstall Error: "The setup must update files or services..."

      When attempting to uninstall PowerShell Universal (MSI Install) from Control Panel -> Programs you receive the error: "The setup must update files or services that cannot be updated while the system is running. If you choose to continue, a reboot ...
    • KB - 1008 Tax/VAT Exempt at checkout

      Scope In this article you will learn how to make a tax-free purchase at checkout. Problem How do you remove the Tax/VAT on an order? Impact Orders will then need to be refunded for tax if processed without the tax deducted. Resolution Follow the ...
    • KB0056 - App Pages Are Missing After Service Restart

      Affected Versions - PowerShell Universal 4.0.0 through 4.2.5 Problem When restarting the PowerShell Universal service, pages that were defined in Apps are no longer displayed in the admin console. The apps are still functional, but they cannot be ...
    • KB0069 - PowerShell Universal Startup Process

      Purpose The purpose of this document is to outline the steps that PowerShell Universal takes when starting up. Process 1. Insert current product version and install date in database Updates the database with a record about the current product version ...