# LibTmux\New-TmuxWindow

- **Package:** LibTmux
- **Language:** PowerShell
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/src/LibTmux.PowerShell/NewTmuxWindowCommand.cs#L9
- **Page:** https://libtmux.org/en/powershell/latest/reference/libtmux-new-tmuxwindow/

```
New-TmuxWindow
    [-Session] <LibTmux.Session>
    [-Name <System.String>]
    [-Index <System.Nullable[System.Int32]>]
    [-StartDirectory <System.String>]
    [-Command <System.String>]
    [-Environment <System.Collections.IDictionary>]
    [-Activate]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]
```

[`Create`](/en/csharp/latest/reference/libtmux-tmuxcommand-create/) a window in an explicit session.

[`Create`](/en/csharp/latest/reference/libtmux-tmuxcommand-create/) a window and its initial pane, then return the captured native
[`LibTmux.Window`](/en/csharp/latest/reference/libtmux-window/). Supply a native [`Session`](/en/csharp/latest/reference/libtmux-session/) directly or through the pipeline. The
new window remains unselected unless Activate is present. The existing session
object is not refreshed in place.

### Notes

[`WhatIf`](/en/powershell/latest/reference/libtmux-new-tmuxwindow/#LibTmux%5CNew-TmuxWindow.parameter.WhatIf) performs no core discovery or dispatch and returns no created object.
Confirmation precedes the core operation. The caller remains responsible for
created resources. Cancellation does not prove that creation was rolled back; no
mutation is retried. Per-owner errors use [`Tmux.WindowCreateFailed`](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/reference/LibTmux/New-TmuxWindow.md#notes) and retain the
core exception and failed session. [`ErrorAction`](/en/powershell/latest/reference/libtmux-new-tmuxwindow/#LibTmux%5CNew-TmuxWindow.parameter.ErrorAction) Continue allows later owners to
run.

## Command details

- **Command type:** [`cmdlet`](/en/powershell/latest/reference/glossary/#cmdlet)
- **Confirmation:** Supports `-WhatIf` and `-Confirm`; confirm impact: Medium.
- **Positional binding:** Enabled.
- **Pipeline inputs:** `LibTmux.Session`: Native pipeline type for this command.
- **Outputs:** `LibTmux.Window`

Related APIs:

- [Task guide](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/create.md)

## Examples

Example 1

Create a named window at an unused index in the first session on the server
identified by $SocketPath. This example requires /bin/sh and leaves the new
window running for later work.

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

```powershell
LibTmux\New-TmuxServer -SocketPath $SocketPath |
    LibTmux\Get-TmuxSession | Select-Object -First 1 |
    LibTmux\New-TmuxWindow -Name 'help-window' -Index 5 -Command 'exec /bin/sh'
```

## Parameters

- `Session` (`LibTmux.Session`): Native session that owns the new window. This is the only pipeline-bound
parameter; binding by an object's Session property is not supported.
  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`): Window name. Omit it to retain tmux's default naming behavior. tmux's format
expansion rules apply.
  Optional. Named parameter. Does not accept pipeline input. [`ValidateNotNullOrEmpty()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnulloremptyattribute?view=powershellsdk-7.4.0).
- `Index` (`System.Nullable[System.Int32]`): Unused session-relative window index, at least 0. Omit it to let tmux choose an
available index. An occupied index remains an error.
  Optional. Named parameter. Does not accept pipeline input. [`ValidateRange(0, 2147483647)`](https://learn.microsoft.com/dotnet/api/system.management.automation.validaterangeattribute?view=powershellsdk-7.4.0).
- `StartDirectory` (`System.String`): Working directory for the new pane. Use an absolute filesystem path for
predictable behavior. The core expands ~ and ~/; this cmdlet does not resolve
PowerShell provider paths or change the host's current directory.
  Optional. Named parameter. Does not accept pipeline input. [`ValidateNotNullOrEmpty()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnulloremptyattribute?view=powershellsdk-7.4.0).
- `Command` (`System.String`): One shell-command string for the new pane. tmux interprets shell syntax in this
string; it is not an argument array. Omit it to use the configured default
command or shell.
  Optional. Named parameter. Does not accept pipeline input. [`ValidateNotNullOrEmpty()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnulloremptyattribute?view=powershellsdk-7.4.0).
- `Environment` (`System.Collections.IDictionary`): A dictionary with string names and string values. Names must be nonempty and
contain neither '=' nor NUL (U+0000). Values may be empty but must not contain
NUL. Null or non-string entries are rejected before confirmation or dispatch.
Entries are copied for this invocation and do not change the PowerShell host
environment.
  Optional. Named parameter. Does not accept pipeline input. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0).
- `Activate` (`System.Management.Automation.SwitchParameter`): Select the new window in its session. By default the current selection is
preserved. This switch does not attach the PowerShell process to a tmux
terminal.
  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`): Runs the command in a mode that only reports what would happen without performing the actions.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input. Aliases: `wi`.
- `Confirm` (`System.Management.Automation.SwitchParameter`): Prompts you for confirmation before running the cmdlet.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input. Aliases: `cf`.

## Returns

`LibTmux.Window`: Captured native object for the created resource.
