View Single Post
Old 07-27-2007   #9 (permalink)
Kiron


 
 

Re: Pecursive Delete Implementation in PowerShell

You can find out more on aliases by typing:
help about_alias

PowerShell is indeed a great shell/language. One of its features is that all
Cmdlets' parameters can be named by their first characters --instead of the
full name-- as long as they disambiguate, or clearly identify, the parameter
with the least amount of characters.

There are also aliases for half of the ubiquitous parameters, better known
as 'common' parameters.

Ubiquitous parameter, Alias
---------------------------
Confirm
Debug
ErrorAction, ea
ErrorVariable, ev
OutBuffer, ob
OutVariable, ov
Verbose
WhatIf

This function will get a sorted list of the regular and common parameters of
a standard Cmdlet. With this list you can see which parameters can be named
with just their first character, or if you need to type its second and third
to clearly identify them. There is at least one other alias I'm aware of,
for New-Item's -itemType regular parameter you can use -type; there may be
more.

function Get-ParameterList
([string]$cmdlet = $(throw "Specify a PowerShell Cmdlet"))
{
if (@(powershell -noProfile {get-command -type Cmdlet | %
{$_.Name}}) -contains $cmdlet)
{
((get-command $cmdlet).definition).split() -match '\[-[a-z]+' -replace
'\[*-|\]' | sort -unique
}
else {"$cmdlet is not a standard Cmdlet"}
}

set-alias gpl Get-ParameterList

# list all parameters, regular and common
# note the use of the just created alias
gpl Get-ChildItem
Debug
ErrorAction
ErrorVariable
Exclude
Filter
Force
Include
LiteralPath
Name
OutBuffer
OutVariable
Path
Recurse
Verbose

According to the this list, and the implementation of common parameters'
aliases, for Get-ChildItem you can use:
-Debug or -d
-ErrorAction or -ea
-ErrorVariable or -ev
-Exclude or -ex
-Filter or -fi
-Force or -fo
-Include or -i
-LiteralPath or -l
-Name or -n
-OutBuffer or -ob
-OutVariable or -ov
-Path or -p
-Recurse or -r
-Verbose or -v

---
Kiron

My System SpecsSystem Spec