> For the complete documentation index, see [llms.txt](https://mohab-yehia.gitbook.io/sec505/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mohab-yehia.gitbook.io/sec505/welcome-to-securing-windows-with-powershell-a-deep-dive-into-sec505/sec-505.1/aliases-in-powershell.md).

# Aliases in PowerShell

## Aliases in PowerShell:&#x20;

Aliases in PowerShell are like nicknames for commands—shorter names for cmdlets, functions, scripts, or executables you use often. They save time and ease the transition from other shells like CMD or UNIX. This guide walks you through understanding, finding, creating, and managing aliases step by step. Let’s get you typing faster!

***

### Step 1: Understanding What Aliases Are

#### Purpose

Grasp the concept of aliases and why they’re useful in PowerShell.

#### Technical Details

* **Definition:** An alias is a shorthand name for a cmdlet (e.g., `dir` for `Get-ChildItem`).
* **Behavior:** Runs the same as the target command.
* **Examples from Image:** `dir` → `Get-ChildItem`, `ps` → `Get-Process`.

#### Why It Matters

* **Speed:** Shorter names mean less typing in interactive sessions.
* **Familiarity:** Bridges UNIX (`ls`) or CMD (`dir`) users to PowerShell.
* **Efficiency:** Boosts productivity for frequent tasks.

**Try It:** Type `dir`—notice it lists files like `Get-ChildItem`?

<figure><img src="https://2325329360-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxV3NRyPsEjkbBdVUnFZk%2Fuploads%2FTuYbdJAt2S0oBvtbTIKd%2Fimage.png?alt=media&amp;token=cf1fa5b5-9802-4fc5-9371-3e8d332a04a9" alt=""><figcaption></figcaption></figure>

***

### Step 2: Discovering Existing Aliases

#### Purpose

Find all aliases or check a specific one in your current session.

#### Technical Details

* **Commands:**
  * `Get-Alias *`: Lists all defined aliases (e.g., `dir`, `ps`).
  * `Get-Alias cd`: Shows the target cmdlet (e.g., `Set-Location`).
* **Output:** Table with "Alias" and "Cmdlet" columns (see image).

#### Why It Matters

* **Exploration:** See what shortcuts are already available.
* **Clarity:** Confirm what an alias (e.g., `ls`) maps to.
* **Awareness:** Helps avoid confusion with unfamiliar aliases.

**Try It:** Run `Get-Alias *`—scroll through the list. Then try `Get-Alias ps`.

<figure><img src="https://2325329360-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxV3NRyPsEjkbBdVUnFZk%2Fuploads%2F4C0ws7bL0jKqsBXhvGzz%2Fimage.png?alt=media&amp;token=7f185742-547f-4c40-94ca-24fe1abd5228" alt=""><figcaption></figcaption></figure>

***

### Step 3: Creating a New Alias

#### Purpose

Define a custom alias for a command or executable.

#### Technical Details

* **Command:** `New-Alias nn notepad.exe`
  * Creates alias `nn` for `notepad.exe`.
* **Syntax:** `New-Alias <AliasName> <Target>`
* **Scope:** Applies only to the current session.

#### Why It Matters

* **Customization:** Tailor shortcuts to your workflow (e.g., `nn` for quick Notepad access).
* **Convenience:** Saves time on repetitive tasks.
* **Flexibility:** Works for cmdlets or executables.

**Try It:** Run `New-Alias nn notepad.exe`, then type `nn`—Notepad should open!

<figure><img src="https://2325329360-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxV3NRyPsEjkbBdVUnFZk%2Fuploads%2FXRxcavwxxyNq3y0ybqJt%2Fimage.png?alt=media&amp;token=73266c6a-3890-4f92-83da-17d390a39fc4" alt=""><figcaption></figcaption></figure>

***

### Step 4: Modifying an Existing Alias

#### Purpose

Update an alias to point to a different target.

#### Technical Details

* **Command:** `Set-Alias nn netsh.exe`
  * Changes `nn` from `notepad.exe` to `netsh.exe`.
* **Behavior:** Overwrites the previous target.

#### Why It Matters

* **Adaptability:** Reassign aliases as your needs change.
* **Control:** Fix or redirect shortcuts easily.
* **Efficiency:** Avoid creating new aliases unnecessarily.

**Try It:** Run `Set-Alias nn netsh.exe`, then type `nn`—it should launch `netsh` now.

<figure><img src="https://2325329360-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxV3NRyPsEjkbBdVUnFZk%2Fuploads%2FfFw85l7MP4vYlAmj1YJE%2Fimage.png?alt=media&amp;token=44021030-83b2-4098-b4f4-2347d3540054" alt=""><figcaption></figcaption></figure>

***

### Step 5: Learning More with `about_alias`

#### Purpose

Dive into detailed documentation on aliases.

#### Technical Details

* **Command:** `help about_alias`
* **Content:** Explains alias creation, management, and best practices.
* **Source:** Plaintext file in `$pshome\en-us\about_alias.help.txt`.

#### Why It Matters

* **Depth:** Understand alias rules and limitations.
* **Guidance:** Learn how to use them effectively.
* **Reference:** Keeps you informed for advanced scripting.

**Try It:** Run `help about_alias`—read through the insights.

<figure><img src="https://2325329360-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxV3NRyPsEjkbBdVUnFZk%2Fuploads%2FRRisfVC3ljVtjzV7lgPN%2Fimage.png?alt=media&amp;token=eafaefda-02c6-41c7-932a-04561fde529f" alt=""><figcaption></figcaption></figure>

***

### Step 6: Making Aliases Permanent

#### Purpose

Ensure aliases persist across PowerShell sessions.

#### Technical Details

* **Issue:** Aliases like `nn` vanish when you close PowerShell.
* **Solution:** Add to your profile script (e.g., `New-Alias nn notepad.exe`).
* **Next Step:** Profile setup covered in a separate section.

#### Why It Matters

* **Consistency:** Reuse your custom aliases every session.
* **Automation:** Streamlines your workflow long-term.
* **Setup:** Prepares you for advanced configuration.

**Try It:** After creating `nn`, close and reopen PowerShell—gone? Note to add it to your profile later.

***
