Skip to content

Commit

Permalink
Update New-Alias.md to fix typo, improve clarity, and add new example
Browse files Browse the repository at this point in the history
I found a typo in the Example 2 explanation. Also, since I was adjusting that text, I modified the text for improved clarity. Also, I added Example 3 to show how to use a custom function with an alias since the New-Alias cmdlet will not take a Value other than a cmdlet or an executable in the form of a string value.
  • Loading branch information
stevenjudd authored May 30, 2024
1 parent b68c2e4 commit 7edd136
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions reference/7.4/Microsoft.PowerShell.Utility/New-Alias.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,37 @@ You can use the `Export-Alias` cmdlet to save your alias information to a file.

### Example 1: Create an alias for a cmdlet

```
```powershell
New-Alias -Name "List" Get-ChildItem
```

This command creates an alias named List to represent the Get-ChildItem cmdlet.

### Example 2: Create a read-only alias for a cmdlet

```
```powershell
New-Alias -Name "C" -Value Get-ChildItem -Description "quick gci alias" -Option ReadOnly
Get-Alias -Name "C" | Format-List *
```

This command creates an alias named `C` to represent the `Get-ChildItem` cmdlet. It creates a
description, quick wmi alias, for the alias and makes it read-only. The last line of the command
description of "quick gci alias" for the alias and makes it read-only. The last line of the command
uses `Get-Alias` to get the new alias and pipes it to Format-List to display all of the information
about it.

### Example 3: Create an alias for a command with parameters

```powershell
function Set-ParentDirectory {Set-Location -Path ..}
New-Alias -Name .. -Value Set-ParentDirectory
```

The first command creates the function `Set-ParentDirectory`, which uses `Set-Location` to set the
working location to the parent directory. The second command uses `New-Alias` to create an alias
of `..` to call the `Set-ParentDirectory` function. Since the Value parameter requires a cmdlet,
function, or executable value, you must create a custom function to create an alias that uses
parameters. Running the alias `..` will set the working location to the parent directory.

## PARAMETERS

### -Description
Expand Down

0 comments on commit 7edd136

Please sign in to comment.