fbpx Program: Learn Aliases for Common Windows Shell Commands | Windows PowerShell, Windows Server | HostingUltraso.com
24/7/365 Support

Program: Learn Aliases for Common Windows Shell Commands

In interactive use, full cmdlet names (such as GetChildItem) are cumbersome and slow to type. Although aliases are much more efficient, it takes awhile to discover them. To learn aliases more easily, you can modify your prompt to remind you of the shorter version of any aliased commands that you use.

This involves two steps:

1. Add the program, GetAliasSuggestion.ps1, to your tools directory or other directory.

Example 19. GetAliasSuggestion.ps1

############################################################################## ## ## GetAliasSuggestion.ps1 ## ## Get an alias suggestion from the full text of the last command ## ## ie: ## ## PS > GetAliasSuggestion RemoveItemProperty ## Suggestion: An alias for RemoveItemProperty is rp ## ##############################################################################

param($lastCommand)

$helpMatches = @( )

## Get the alias suggestions foreach($alias in GetAlias) {

if($lastCommand match ("\b" + [System.Text.RegularExpressions.Regex]::Escape($alias.Definition) + "\b")) { $helpMatches += "Suggestion: An alias for $($alias.Definition) is $($alias.Name)" } }

$helpMatches

2. Prompt function in your profile. If you already have a prompt function, you only need to add the content from inside the prompt function of

A useful prompt to teach you aliases for common commands

function Prompt

{ ## Get the last item from the history $historyItem = GetHistory Count 1

## If there were any history items if($historyItem) {

## Get the training suggestion for that item $suggestions = @(GetAliasSuggestion $historyItem.CommandLine)

Example 110. A useful prompt to teach you aliases for common commands (continued)

## If there were any suggestions if($suggestions) {

## For each suggestion, write it to the screen foreach($aliasSuggestion in $suggestions) {

WriteHost "$aliasSuggestion" } WriteHost ""

} }

## Rest of prompt goes here "PS [$env:COMPUTERNAME] >" }

Help Category:

Get Windows Dedicated Server

Only reading will not help you, you have to practice it! So get it now.

Processor RAM Storage Server Detail
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 1 TB (HDD SATA) Configure Server
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 128 GB (SSD SATA) Configure Server
Intel Atom C2750 2.4 GHz 8c/8t 8 GB DDR3 1× 1 TB (HDD SATA) Configure Server
Intel Xeon E3-1230 v2 3.3 GHz 4c/8t 16 GB DDR3 1× 256 GB (SSD SATA) Configure Server
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 250 GB (SSD SATA) Configure Server

What Our Clients Say