KB0071 - Apps and APIs restart when changing variables in PowerShell Universal

KB0071 - Apps and APIs restart when changing variables in PowerShell Universal

Scope

This applies to users who change variable values on their PowerShell Universal environments during runtime. This affects all versions of PowerShell Universal. 

Problem

Apps and APIs will restart when variables are changed. This can cause users to lose work and appear they have been disconnected from apps. It can cause APIs to lose cache data. 

Root Cause

This behavior is currently by design. When runspaces to execute PowerShell are created in PowerShell Universal, variables are set to their values. Instead of reading the variable values during each execution, the variables are present in the default state of the runspace. This provides a performance increase since the variables do not need to be set with every execution. When variables change, PowerShell Universal will restart processes or recycle runspace pools to populate the runspace with new variable states. This causes apps and the API processes to restart.

Workaround

To work around this issue, you can do the following. 

Apps

Disabling auto reload on apps will prevent this from happening. Do note, new variable values will not be reflected in apps until they are restarted. 

APIs

The issue with APIs is that they may lose cached data stored in the $Cache scope. Typically, APIs do not maintain state but the $Cache scope is an exception. To avoid losing data, use Set-PSUCache instead. This stores cached data within the server and will survive restarts of the API service. 
    • Related Articles

    • PowerShell Universal Service crashes on startup after an upgrade to 1.4.6

      Version: PowerShell Universal 1.4.6 Issue The PowerShell Universal service will crash with the following error in Event Viewer.  Application: Universal.Server.exe CoreCLR Version: 4.700.19.56402 .NET Core Version: 3.1.0 Description: The process was ...
    • 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 ...
    • KB0036 - How to set the license via environment variable

      Purpose The purpose of this article is to explain how to set the license for PowerShell Universal by way of environment variable instead of the traditional file-based method. Scope For now, only Windows is in the scope of this article. Linux and ...
    • KB0034 - How to collect logs

      Purpose The purpose of this article is to provide clear ordered steps for users of PowerShell Universal and to submit them to Ironman Software (typically for a support case). Background Having logs from PowerShell Universal is typically needed to ...
    • KB0049 - Failure to login after changing security environment

      Problem Changing from a security environment, such as Windows PowerShell, to the integrated environment may cause users to fail to be able to login. The login button will appear to do nothing when clicked. Root Cause Changing the security environment ...