The good
news is that most of the commands have short versions, called aliases, that
just happen to coincide with familiar DOS and Unix command names. For
instance, instead of typing Copy-Item, you can type copy (as in DOS) or cp (?
la Unix) to copy files from one place to another; if nothing else, this dualism
is an important advantage over the conventional Command Prompt.
Table 9-1 shows a list of common, basic PowerShell commands, and their
DOS and Unix counterparts.
Figure 9-4. Microsoft PowerShell, a free, powerful alternative to the Command Prompt,
also supports scripting
566 | Chapter 9: Scripting and Automation
What??™s more enticing is that you can make your own aliases. For example, if
you find yourself frequently using the Get-Culture command (which
retrieves the language in use by Windows), you could shorten it like this:
Set-Alias -Name lang -Value Get-Culture
so that you could thereafter type only lang to display the current language.
The Set-Alias command also lets you change (overwrite) any of the built-in
aliases.
The Set-Alias command only creates aliases for bare commands;
you can??™t bury your favorite command-line parameters
in an alias. To replace a complex, multipart command
with a single word you can type at the prompt, use Power-
Shell variables, discussed later.
Of course, once you close the current PowerShell window, your custom alias
will be forgotten. So, to save your custom aliases from session to session,
add your Set-Alias commands to your PowerShell profile file.
Pages:
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788