For the complete documentation index, see llms.txt. This page is also available as Markdown.

New-PSUEnvironment

Creates a new PowerShell Universal environment.

SYNOPSIS

Creates a new PowerShell Universal environment.

SYNTAX

New-PSUEnvironment -Name <String> [-Version <String>] [-Type <EnvironmentType>] [-Path <String>]
 [-Arguments <String>] [-Modules <String[]>] [-Variables <String[]>] [-PSModulePath <String[]>]
 [-StartupScript <String[]>] [-PersistentRunspace] [-RunspaceRecycling] [-MaxRunspaces <Int32>]
 [-MaxVirtualMemory <Int64>] [-RecycleSchedule <String>] [-Credential <Variable>] [-Description <String>]
 [-DisableImplicitWinCompat] [-Minimal] [-Disabled] [-ProcessStartupScript <String>] [-EnableDebugger]
 [-Verb <String>] [-ComputerName <String>] [-AppToken <String>] [-UseDefaultCredentials] [-Integrated]
 [-TrustCertificate] [-Cookies] [<CommonParameters>]

DESCRIPTION

Environments define PowerShell execution environments within PowerShell Universal. You can use them when executing APIs, Scripts, Dashboards and the security processes for authentication and authorization.

Environments are stored within the ./universal/environments.ps1 file.

You can also use this cmdlet to create environments through the REST API.

EXAMPLES

Example 1

Creates a new environment called 7.1 that uses the pwsh.exe for running APIs, scripts or dashboards.

Example 2

Creates a new environment called 7.1 that uses the pwsh.exe executable and sets the execution policy to ByPass.

Example 3

Creates a new environment that uses all the variables defined with New-PSUVariable.

Example 4

Creates a new environment that automatically loads the ActiveDirectory module.

Example 5

Creates a new environment that uses persistent runspaces. Persistent runspaces are used for APIs and do not reset between each execution.

PARAMETERS

-AppToken

The AppToken that is used for calling the PowerShell Universal Management API. You can also call Connect-PSUServer before calling this cmdlet to set the AppToken for the entire session.

-Arguments

Arguments to pass to the PowerShell process when starting the environment.

-ComputerName

Specifies the computer name or URL that should be called when accessing the PowerShell Universal Management API. You can also use Connect-PSUServer before calling this cmdlet to set the computer name for the entire session.

-Modules

Modules to automatically load when creating new runspaces in the environment.

-Name

The name of the environment.

-PSModulePath

Additional paths to add to the PSModulePath for the environment.

-Path

The path to the PowerShell executable.

-PersistentRunspace

Whether to enable persistent runspaces. This is only used for APIs.

-Variables

Variables to import into the runspace. These are variables defined by New-PSUVariable.

-UseDefaultCredentials

Use default credentials when connecting to the management API

-Integrated

Executes the command internally rather than using the Management API. Only works when running script from within PowerShell Universal.

-StartupScript

A script to run when creating the runspaces in this environment.

-Version

A version number to display.

-RunspaceRecycling

Whether to recycle runspaces. Runspaces will be recycled (disposed and recreated) after an amount of time or a number of uses.

-MaxRunspaces

The maximum number of runspaces to create for this environment.

-EnableDebugger

Enables the PowerShell debugging feature for this environment.

-Credential

The credential to use with this environment

-MaxVirtualMemory

The maximum virtual memory in bytes. When the threshold is reached, the process is restarted. Ignored for the integrated environment.

-RecycleSchedule

A CRON schedule to restart this environment. Ignored for the integrated environment.

-Description

A description for this environment.

-DisableImplicitWinCompat

Disables Windows PowerShell Implicit Compatibility mode.

-Minimal

A minimal environment that does not load any modules or variables.

-ProcessStartupScript

A script that runs once when the process starts. This is not run for each runspace.

-Disabled

Environment is disabled.

-TrustCertificate

Whether the cmdlet should ignore certificate issues.

-Type

The type of environment. PowerShell 7 and Windows PowerShell 5.1 are supported. Use Custom to create a custom environment

-Verb

The verb to use when creating the process for this environment. This is not used for the integrated environment.

-Cookies

Reuses and persists authentication cookies for the current PowerShell session.

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -Verbose, -WarningAction, -WarningVariable, and -ProgressAction. For more information, see about_CommonParameters.

INPUTS

None

OUTPUTS

System.Object

NOTES

New-PSUVariable

Last updated

Was this helpful?