> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/powershell-universal/config/environments.md). Agents can also search and read this documentation through its [MCP server](https://docs.devolutions.net/~gitbook/mcp).

# Environments

Configure PowerShell Universal execution environments, including isolated PowerShell versions, virtual environments, Devolutions Agent, and minimal mode.

By default, authentication and authorization happen within the `Universal.Server.exe` process. To run these from a different process, you can select an environment by setting the `-SecurityEnvironment` parameter of `Set-PSUSetting` in `settings.ps1`. See [Security](https://docs.devolutions.net/powershell-universal/security/security.md#environment) for more information on this. PowerShell Universal waits up to 30 seconds for this security process to start; change the wait with the `Authentication:SecurityProxyTimeout` setting in [appsettings.json](https://docs.devolutions.net/powershell-universal/config/settings.md).

Execution environments define the PowerShell runtime, modules, variables, and execution settings used by scripts, APIs, apps, automation jobs, and security processes. Manage them under **Manage > Environments > Environments** or in `environments.ps1`.

## Choose an environment type

| Type                    | Use                                                                                                                                               |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| Integrated              | Runs directly in the PowerShell Universal server process.                                                                                         |
| PowerShell 7            | Uses the PowerShell 7 host included with PowerShell Universal.                                                                                    |
| PowerShell 7 (Isolated) | Uses [multi-pwsh](https://github.com/Devolutions/multi-pwsh) to run a selected PowerShell 7 version, optionally in a managed virtual environment. |
| Windows PowerShell 5.1  | Uses the Windows PowerShell runtime installed on the server.                                                                                      |
| Custom                  | Starts the executable and arguments you specify.                                                                                                  |
| Container               | Runs in the configured Devolutions Agent container image.                                                                                         |

All environments can define modules, PowerShell variables, `PSModulePath` entries, startup scripts, and advanced runspace settings. Select an environment by name when configuring a script, schedule, API, app, terminal, or security environment.

## Configure resources

Use the **Resources** tab when editing an environment to configure these settings:

* **Modules**: Module names or module-file paths that PowerShell Universal imports when it creates runspaces.
* **Variables**: Names of PowerShell Universal variables to make available. Use `*` to include all matching variables.
* **PSModulePath**: Additional module-search paths for the environment.

Startup scripts are set on the **Advanced** tab:

* **Startup scripts**: Repository-relative scripts that run when a new runspace is created.

Startup scripts run once for each new runspace. They run once when a job starts, but can run more often for APIs and apps as their runspaces are created. Platform variables are not available in startup scripts.

## Environment settings

The ***Manage*** – ***Environments*** page lists the execution environments for PowerShell Universal features, on two tabs: ***Environments*** and ***PowerShell Versions***. Go to ***Manage*** – ***Environments*** – ***Environments*** and create or edit an environment. The environment dialog has three tabs on its left side: ***General***, ***Resources*** and ***Advanced***. When multi-pwsh cannot run on the server, the dialog shows the warning "Isolated PowerShell environments are not supported on this server because multi-pwsh cannot run: {0}", where `{0}` is the reason, or "The multi-pwsh executable is missing."

### General tab

<table><thead><tr><th width="260">SETTING</th><th>DESCRIPTION</th></tr></thead><tbody><tr><td><em><strong>Name</strong></em></td><td>"A friendly name for this resource."</td></tr><tr><td><em><strong>Description</strong></em></td><td>A description of the environment.</td></tr><tr><td><em><strong>Type</strong></em></td><td>"The type of environment that this configuration will use." The choices are <em><strong>PowerShell 7</strong></em>, <em><strong>PowerShell 7 (Isolated)</strong></em>, <em><strong>Container</strong></em>, <em><strong>Windows PowerShell 5.1</strong></em> and <em><strong>Custom</strong></em>. The Integrated environment is built in and is not one of the choices.</td></tr><tr><td><em><strong>PowerShell Version</strong></em></td><td>Shown and required for <em><strong>PowerShell 7 (Isolated)</strong></em>. "The isolated PowerShell version or selector to run with multi-pwsh." The list holds the versions marked <em><strong>Isolated</strong></em> on the <em><strong>PowerShell Versions</strong></em> tab.</td></tr><tr><td><em><strong>Virtual</strong></em></td><td>Shown for <em><strong>PowerShell 7 (Isolated)</strong></em> and <em><strong>Container</strong></em>. "Create and use an isolated multi-pwsh virtual environment for this execution environment." Cleared by default. See <a href="#managed-virtual-environments">Managed virtual environments</a>.</td></tr><tr><td><em><strong>Path</strong></em></td><td>Shown for <em><strong>Custom</strong></em>. "The absolute or relative path to an executable to launch for this environment. For example: pwsh.exe"</td></tr><tr><td><em><strong>Arguments</strong></em></td><td>Shown for <em><strong>Custom</strong></em>. "Arguments to pass to the executable when starting this environment."</td></tr><tr><td><em><strong>Minimal</strong></em></td><td>Shown for <em><strong>PowerShell 7</strong></em>, <em><strong>Windows PowerShell 5.1</strong></em> and <em><strong>Custom</strong></em>. "Minimal environments do not load PowerShell Universal assemblies and can support other languages. They are only support with jobs." Cleared by default. See <a href="#powershell-7-minimal-environments">PowerShell 7 minimal environments</a>.</td></tr><tr><td><em><strong>Container Image URL</strong></em></td><td>Shown for <em><strong>Container</strong></em>. "Optional registry or repository URL for the container image. Leave empty to use Docker Hub." Example: <code>ghcr.io/devolutions</code>.</td></tr><tr><td><em><strong>Container Image Tag</strong></em></td><td>Shown for <em><strong>Container</strong></em>. "Image name and tag to run, such as devolutions-agent:latest."</td></tr><tr><td><em><strong>Pull Container Image</strong></em></td><td>Shown for <em><strong>Container</strong></em>. "Pull the image before starting each job." Cleared by default.</td></tr><tr><td><em><strong>Disabled</strong></em></td><td>Disables the environment. Cleared by default.</td></tr></tbody></table>

### Resources tab

<table><thead><tr><th width="260">SETTING</th><th>DESCRIPTION</th></tr></thead><tbody><tr><td><em><strong>Modules to Import</strong></em></td><td>"The modules to import when creating runspaces in this environment." Type a module name or a module-file path and press Enter to add it.</td></tr><tr><td><em><strong>Variables</strong></em></td><td>"Variables to define in the environment." Pick the names of PowerShell Universal variables, or <code>*</code> for all of them.</td></tr><tr><td><em><strong>PSModulePath</strong></em></td><td>"Additional PSModulePath folders to add to the environment."</td></tr></tbody></table>

### Advanced tab

<table><thead><tr><th width="260">SETTING</th><th>DESCRIPTION</th></tr></thead><tbody><tr><td><em><strong>Disable Implicit Windows Compatibility</strong></em></td><td>"Disables implicit Windows compatbility in PowerShell 7." Cleared by default. See <a href="#windows-powershell-compatibility">Windows PowerShell compatibility</a>.</td></tr><tr><td><em><strong>Maximum Runspace Count</strong></em></td><td>"The maximum number of runspaces to start in a multi-runspace environment like PowerShell Apps and APIs." Default: <code>25</code>.</td></tr><tr><td><em><strong>Runspace Saturation Warning Threshold (%)</strong></em></td><td>"The runspace pool utilization percentage that must be exceeded before a saturation warning can be emitted." Allowed values: 1 to 100. Default: <code>80</code>.</td></tr><tr><td><em><strong>Runspace Saturation Warning Duration (Seconds)</strong></em></td><td>"How long runspace utilization must remain above the warning threshold before an in-console saturation warning is generated." Minimum: 1. Default: <code>30</code>.</td></tr><tr><td><em><strong>Maximum Virtual Memory</strong></em></td><td>"The maximum virtual memory (in megabytes) processes in this environment are allowed to be before they are terminated." Default: <code>0</code>.</td></tr><tr><td><em><strong>Persistent Runspaces</strong></em></td><td>"Prevents runspaces from resetting state between invocations. Apps, APIs, and automation scripts reuse a runspace pool for this environment." Cleared by default.</td></tr><tr><td><em><strong>Startup Scripts</strong></em></td><td>"Scripts that are run any time a new runspace is created in this environment." Pick one or more scripts of the repository.</td></tr><tr><td><em><strong>Process Startup Script</strong></em></td><td>"A script that runs when the environment is process is started." Pick one script of the repository, or clear the field.</td></tr><tr><td><em><strong>Run As</strong></em></td><td>"The user credential to run as."</td></tr><tr><td><em><strong>Verb</strong></em></td><td>"Only valid on Windows. The verb used when starting this environment's process."</td></tr><tr><td><em><strong>Recycle Schedule</strong></em></td><td>"A CRON expression used to control how frequently resources in this environment are restarted. If blank, environment recycling will not occur." Example: <code>*/5 * * * *</code>. Empty by default. A valid expression replaces the help text with a plain-language description of the schedule; an invalid one shows "Invalid CRON expression."</td></tr></tbody></table>

## PowerShell 7 isolated environments

An isolated environment uses multi-pwsh instead of the PowerShell host included with PowerShell Universal. Choose this type when a script needs a specific PowerShell 7 release or stronger process isolation from the server's PowerShell SDK and loaded assemblies.

Every isolated environment must have a **PowerShell version**. PowerShell Universal rejects an isolated environment that does not specify one with the error `A PowerShell version is required for isolated environments.`, and a job started in such an environment fails with `Isolated environments require a PowerShell version.`

### Install and select PowerShell versions

1. Go to **Manage > Environments > PowerShell Versions**.
2. Enter a multi-pwsh selector such as `stable`, `preview`, `lts`, or `7.4`, then select **Install**.
3. Refresh the version list. It shows each version, its path, and whether it is available for isolated environments.
4. Create or edit an environment, select **PowerShell 7 (Isolated)**, and select an installed isolated version.

Only versions marked **Isolated** are selectable for isolated environments. You can remove multi-pwsh-installed versions from the same tab when they are no longer needed.

#### PowerShell Versions tab

The ***Manage*** – ***Environments*** – ***PowerShell Versions*** tab lists the PowerShell versions of the server. The selector box is filled with `stable` by default. ***Install*** and ***Remove*** require the permission to create and delete environments; the console shows "Installed" or "Removed" when the action ends, or the error message when it fails. ***Refresh*** reloads the list.

<table><thead><tr><th width="200">COLUMN</th><th>DESCRIPTION</th></tr></thead><tbody><tr><td><em><strong>Actions</strong></em></td><td><em><strong>Remove</strong></em>, shown only for versions that multi-pwsh can remove.</td></tr><tr><td><em><strong>Name</strong></em></td><td>The name of the PowerShell installation.</td></tr><tr><td><em><strong>Version</strong></em></td><td>The PowerShell version.</td></tr><tr><td><em><strong>Path</strong></em></td><td>The path of the PowerShell executable.</td></tr><tr><td><em><strong>Isolated</strong></em></td><td>A green check: "This PowerShell version is managed by multi-pwsh and can be used by isolated environments." A grey information icon: "This PowerShell version is available outside of multi-pwsh."</td></tr></tbody></table>

The tab can show these messages:

* "Isolated PowerShell environments are not supported on this server because multi-pwsh cannot run: {0}" or "The multi-pwsh executable is missing." (warning): multi-pwsh cannot run on the server.
* "PowerShell version installation is unavailable because multi-pwsh is missing or the release service cannot be reached." (information, shown to users who can create environments): ***Install*** is not available.

Create an isolated environment in configuration with a concrete version or a multi-pwsh selector:

```powershell
New-PSUEnvironment `
    -Name 'Isolated PowerShell 7.4' `
    -Type Isolated `
    -PowerShellVersion '7.4'
```

## Managed virtual environments

Enable **Virtual** on an isolated environment to run it in a managed multi-pwsh virtual environment. PowerShell Universal creates the virtual environment before it is used and selects it whenever the environment starts a job.

The managed virtual-environment identity is derived from the environment's name, PowerShell version, modules, `PSModulePath`, and startup-script settings. Changing those settings creates a new managed identity. PowerShell Universal cleans up managed virtual environments that are no longer referenced by an environment.

Use a virtual environment when you want the multi-pwsh runtime state to remain isolated from other environments. Container environments also use a managed virtual environment when **Virtual** is enabled or when the environment has modules configured.

```powershell
New-PSUEnvironment `
    -Name 'Isolated PowerShell 7.4 virtual' `
    -Type Isolated `
    -PowerShellVersion '7.4' `
    -Virtual `
    -Modules @('Az.Accounts')
```

### Devolutions Agent support

When a job targets a connected Devolutions Agent, PowerShell Universal uses the environment's PowerShell version selector with the agent's multi-pwsh executable. For an isolated or container environment that uses a managed virtual environment, the server exports that virtual environment and the agent imports it before the job starts.

This transfer is automatic and uses a short-lived, authenticated download URL. The agent reuses an already imported matching virtual environment. Configure the same environment normally, then choose the Devolutions Agent or computer group in the run or schedule options.

## PowerShell 7 minimal environments

Enable **Minimal** on a PowerShell 7 environment to run jobs in a dedicated PowerShell subprocess through local PowerShell remoting. This mode avoids loading the normal PowerShell Universal hosting assemblies into the script process, which is useful for scripts and modules that have assembly-binding conflicts with the server.

Minimal mode is available for PowerShell 7, Windows PowerShell 5.1, and Custom environments. PowerShell Universal retains the job's formatted output and pipeline output from minimal PowerShell 7 runs, so output remains available in the job log and job history.

Minimal environments still have important limitations:

* They do not support feedback, progress reporting, secrets, or Universal integrated cmdlets.
* Configured non-secret variable values are provided as process environment variables.
* Use the normal PowerShell 7 environment when the script needs full PowerShell Universal host integration.

To enable it in the admin console, edit a PowerShell 7 environment and select **Minimal**. In configuration:

```powershell
New-PSUEnvironment `
    -Name 'PowerShell 7 Minimal' `
    -Type PowerShell7 `
    -Minimal `
    -Variables @('*')
```

A Custom minimal environment can run another command-line executable. Use `{scriptPath}` in its arguments when the executable must receive the resolved script path.

```powershell
New-PSUEnvironment `
    -Name 'Python' `
    -Path 'python' `
    -Arguments '{scriptPath}' `
    -Variables @('*') `
    -Minimal
```

## Standard environments

### Integrated

The Integrated environment runs scripts directly in the PowerShell Universal server process. It avoids interprocess serialization and is simple to configure, but cannot run as alternate credentials or use another PowerShell version. Because scripts share the server process, problematic scripts can affect platform stability.

The Integrated environment is always available. You can still configure modules or persistent runspaces for it in `environments.ps1`:

```powershell
New-PSUEnvironment -Name 'Integrated' -Path 'none' -Modules @('ActiveDirectory')
```

### PowerShell 7

The standard PowerShell 7 environment uses the PowerShell host included with PowerShell Universal. It is the recommended default for broad third-party module compatibility. If a script requires Windows Forms or another Windows PowerShell-only dependency, use Windows PowerShell 5.1 or a Custom environment instead.

### Windows PowerShell 5.1

Windows PowerShell 5.1 uses the Windows PowerShell runtime installed on the server. Use it for scripts and modules that require Windows PowerShell.

### Discover installed PowerShell versions

On the ***Environments*** page of the admin console, ***Discover Environments*** — "Discovers environments that are installed on this machine." — creates an environment for each PowerShell version installed on the server that does not already have an environment with the same name. The page shows "Starting environment discovery." The button is available only when the configuration can be edited.

## Use environments across PowerShell Universal

* **APIs**: Set `-ApiEnvironment` with `Set-PSUSetting` in `settings.ps1`.
* **Automation**: Set `-Environment` for scripts and schedules, or select it when starting a job.
* **Apps**: Set `-Environment` with `New-PSUApp`.
* **Security**: Set `-SecurityEnvironment` with `Set-PSUSetting` when authentication and authorization should run outside the server process.

## Windows PowerShell compatibility

PowerShell 7 can automatically use local Windows PowerShell remoting when a command or module is unavailable. This compatibility feature creates a Windows PowerShell process per runspace and can substantially increase process count, memory use, CPU use, and serialization overhead.

Disable implicit Windows PowerShell compatibility in the environment's **Advanced** tab when it is not required. It is disabled for the Integrated environment and cannot be enabled there.

If you must use compatibility, remove the compatibility session after the command completes:

```powershell
Import-Module PSScheduledJob -UseWindowsPowerShell
Get-ScheduledJob | Out-Null
Get-PSSession -Name 'WinPSCompatSession' | Remove-PSSession
```

## PowerShell cmdlets

Manage environments with `New-PSUEnvironment`, `Get-PSUEnvironment`, `Set-PSUEnvironment`, and `Remove-PSUEnvironment`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.devolutions.net/powershell-universal/config/environments.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
