5.3. Aliases

Windows PowerShell supports creating aliases for PowerShell commands (that is, for cmdlets), including the use of parameters. An alias is, essentially, an alternative name used to run a cmdlet.

One reason you might use aliases is that you are familiar with a particular operating system or tool and you wish to use the commands that you are already familiar with to carry out frequently performed tasks. Another reason to use aliases is to save on typing. For example, if you want to retrieve a list of all running processes, you can use the full syntax:

get-process

or with an explicit wildcard:

get-process *

Alternatively, you can use the alias in the command:

gps

or:

gps *

to achieve the same thing.

Similarly, if you want to list files contained in a folder, you can achieve that using the full PowerShell command:

get-childitem

But if you are familiar with the current Microsoft command shell, you might prefer to use:

dir

Or, if you use a Linux shell, you might prefer to use:

ls

Each of those options is shorter than the full syntax and is familiar to large numbers of administrators. These aliases are provided by default in a PowerShell install.

There is a potential trap in the flexibility that PowerShell gives you to create aliases if you attempt to execute scripts that contain aliases in the code but they aren't available on the machine in question. I suggest that you confine ...

Get Professional Windows® PowerShell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.