# LibTmux\Set-TmuxEnvironment

- **Package:** LibTmux
- **Language:** PowerShell
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/src/LibTmux.PowerShell/SetTmuxEnvironmentCommand.cs#L7
- **Page:** https://libtmux.org/en/powershell/latest/reference/libtmux-set-tmuxenvironment/

```
Server (default):
Set-TmuxEnvironment
    [-Server] <LibTmux.Server>
    -Name <System.String>
    -Value <System.String>
    [-ExpandFormats]
    [-Hidden]
    [-PassThru]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Session:
Set-TmuxEnvironment
    [-Session] <LibTmux.Session>
    -Name <System.String>
    -Value <System.String>
    [-ExpandFormats]
    [-Hidden]
    [-PassThru]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]
```

Set a tmux environment variable for future processes or formats.

An empty string sets a present, empty value. [`ExpandFormats`](/en/csharp/latest/reference/libtmux-sendkeysrequest-expandformats/) expands tmux formats
before storage. Hidden keeps the variable for tmux formats and excludes it from
new child process environments and ordinary reads. With Hidden and PassThru, the
native readback entry has Value null and [`IsRemoved`](/en/csharp/latest/reference/libtmux-tmuxenvironmententry-isremoved/) false; this does not mean an
empty or removed variable. Without PassThru, emit no success output. [`WhatIf`](/en/powershell/latest/reference/libtmux-set-tmuxenvironment/#LibTmux%5CSet-TmuxEnvironment.parameter.WhatIf) does
not contact tmux.

### Notes

A [`Server`](/en/csharp/latest/reference/libtmux-server/) selects the global environment; a [`Session`](/en/csharp/latest/reference/libtmux-session/) selects its local environment.
Reads do not merge those tables. Changes affect newly created processes and do not
rewrite the environment of an existing pane process. Empty owner pipelines do no
I/O. Errors retain the original exception and owner; Continue permits later owners
and Stop terminates. Cancellation cannot undo a dispatched mutation.

## Command details

- **Command type:** [`cmdlet`](/en/powershell/latest/reference/glossary/#cmdlet)
- **Default parameter set:** Server
- **Confirmation:** Supports `-WhatIf` and `-Confirm`; confirm impact: Medium.
- **Positional binding:** Enabled.
- **Pipeline inputs:** `LibTmux.Server`: A native server owner.; `LibTmux.Session`: A native session owner.
- **Outputs:** `LibTmux.TmuxEnvironmentEntry`

Related APIs:

- [Environment](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/environment.md)

## Examples

Example 1

Set a value for future processes in a native $session and inspect its readback.

[Source example](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/reference/LibTmux/Set-TmuxEnvironment.md).

```powershell
$session |
    LibTmux\Set-TmuxEnvironment -Name 'APP_MODE' -Value 'development' -PassThru
```

## Parameters

- `Server` (`LibTmux.Server`): The native server whose table is used. (for `Server`)
  Required. Position 0. Accepts pipeline input by value. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0).
- `Name` (`System.String`): The environment variable name. Omit Name on Get to list this table. Whitespace-only names and NUL are rejected.
  Required. Named parameter. Does not accept pipeline input. [`ValidateNotNullOrEmpty()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnulloremptyattribute?view=powershellsdk-7.4.0). [`ValidatePattern("\\A[^\\x00]*[^\\s\\x00][^\\x00]*\\z")`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatepatternattribute?view=powershellsdk-7.4.0).
- `Value` (`System.String`): The value to store. Empty strings are allowed; NUL is rejected.
  Required. Named parameter. Does not accept pipeline input. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0). [`ValidatePattern("^[^\\x00]*$")`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatepatternattribute?view=powershellsdk-7.4.0).
- `ExpandFormats` (`System.Management.Automation.SwitchParameter`): Expand tmux formats in the value before storage.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input.
- `Hidden` (`System.Management.Automation.SwitchParameter`): Keep the variable for tmux formats, excluding it from child environments and ordinary reads.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input.
- `PassThru` (`System.Management.Automation.SwitchParameter`): Emit the native value read back after the mutation. Without this switch, emit no success output. Readback still occurs.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input.
- `Verbose` (`System.Management.Automation.SwitchParameter`): Display verbose messages produced by this command.
  Optional. Named parameter. Switch parameter. Common parameter. Does not accept pipeline input. Aliases: `vb`.
- `Debug` (`System.Management.Automation.SwitchParameter`): Display debug messages produced by this command.
  Optional. Named parameter. Switch parameter. Common parameter. Does not accept pipeline input. Aliases: `db`.
- `ErrorAction` (`System.Management.Automation.ActionPreference`): Choose how this command responds to non-terminating errors.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ea`.
- `WarningAction` (`System.Management.Automation.ActionPreference`): Choose how this command responds to warning messages.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `wa`.
- `InformationAction` (`System.Management.Automation.ActionPreference`): Choose how this command handles information messages.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `infa`.
- `ProgressAction` (`System.Management.Automation.ActionPreference`): Choose how this command handles progress updates.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `proga`.
- `ErrorVariable` (`System.String`): Store the command's error records in the named variable.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ev`.
- `WarningVariable` (`System.String`): Store the command's warning records in the named variable.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `wv`.
- `InformationVariable` (`System.String`): Store the command's information records in the named variable.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `iv`.
- `OutVariable` (`System.String`): Save output in the named variable while passing it down the pipeline.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ov`.
- `OutBuffer` (`System.Int32`): Buffer output before passing it to the next pipeline command.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ob`.
- `PipelineVariable` (`System.String`): Make the most recent output object available through a named variable within the pipeline.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `pv`.
- `WhatIf` (`System.Management.Automation.SwitchParameter`): Show the selected owner, scope and operation without contacting tmux.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input. Aliases: `wi`.
- `Confirm` (`System.Management.Automation.SwitchParameter`): Ask for confirmation before changing the selected table.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input. Aliases: `cf`.
- `Session` (`LibTmux.Session`): The native session whose table is used. (for `Session`)
  Required. Position 0. Accepts pipeline input by value. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0).

## Returns

`LibTmux.TmuxEnvironmentEntry`: The native readback entry, only with PassThru.
