Coding Ref

How to create an alias in PowerShell

How to create an alias in PowerShell

To create an alias in PowerShell, use the New-Alias cmdlet.

This cmdlet takes the name of the new alias and the command or cmdlet that the alias should represent as input, and creates the alias with the specified name and command.

Example

Here is an example of how to create an alias named ls that represents the Get-ChildItem cmdlet:

New-Alias -Name ls -Value Get-ChildItem

This command will create the ls alias, which can be used as a shortcut for the Get-ChildItem cmdlet.

Once the alias has been created, you can use it just like any other cmdlet or command in PowerShell.

For example, you can use the ls alias to list the contents of the current directory by typing the following command:

ls

This command will run the Get-ChildItem cmdlet, which lists the contents of the current directory, using the ls alias as a shortcut. The output of the cmdlet will be displayed in the PowerShell window.

An alias is not a replacement for the original command or cmdlet, but simply a shortcut for it. The original command or cmdlet will continue to exist and can be used as normal, even if an alias has been created for it.

Conclusion

To create an alias in PowerShell, use the New-Alias cmdlet.

You'll also like

Related tutorials curated for you

    How to create new items in PowerShell

    How to add a user to a group in PowerShell

    What is Echo in PowerShell?

    How to use Format-Table in PowerShell

    Switch statement in PowerShell

    How to rename a file in PowerShell

    How to append content to a file in PowerShell

    What is PowerShell logging?

    How to select an object in PowerShell

    How to use -filter in Get-ChildItem in PowerShell

    How to ping in PowerShell

    Everything about certificates in PowerShell