|
Guy recommends :
Find out which of your VMs are a waste of space and which VMs need more resources.
|
Windows PowerShell Get-AliasIntroduction to Windows PowerShell Get-AliasPowerShell has a whole family of Aliases. One group of these aliases provides shorthand for the regular cmdlets, instead of typing thirteen keystrokes for Get-Childitem, just use a PowerShell alias and type the three letters: gci. However, I am going to concentrate on alias cmdlets which are designed to help people migrate from other languages. Thanks to aliases, those who know DOS can still use dir, and those who are familiar with UNIX can still use ls in PowerShell. These old commands work because PowerShell has created an internal link so that when you type dir it translates to the cmdlet Get-ChildItem. PowerShell Alias Topics
♣ A Mission For PowerShell Aliases - Abandon DOSI have a tough mission, to persuade people to abandon the DOS command-line and switch to PowerShell. There are three threads to this mission. 1) Have faith that an alias such as cd will change directory in PowerShell just as it did in DOS. 2) Realize that built-in operating system commands such as Ping, Ipconfig and Shutdown work in PowerShell 98% as well as they did with cmd.exe. Consequently, there is no need to use that DOS box, just use the PowerShell command-line instead. I understand that this is a leap of faith, and to begin with may take you out of your comfort zone. 3) The third aspect of the PowerShell alias cmdlets is how they deal with native operating system commands that need user input. For this task we can employ start-Process, or the versatile PowerShell cmdlet new-Object with its -comObject parameter. This week I just want to make you aware that interactive command-line utilities, such as NetSh will work in PowerShell, however they need techniques outside the scope of this article. In conclusion, my idea is that you will learn PowerShell faster if you use it for familiar DOS tasks. Then gradually, it will become easier and more natural to start incorporating more and more pure PowerShell commands into your working habits. Check Out PowerShell's Get-AliasIn the old days I listed PowerShell's aliases with this command: # Research PowerShell Alias Then I discovered that alias has its own cmdlet: Get-Alias Note 1: The benefit of the PowerShell Get-Alias is that you can investigate more properties by appending | Get-Member, thus: # Research Get-Alias Properties Note 2: Get-Help Get-Alias (Or use the alias 'help' and
try plain: 'help Get-Alias'). Now we have extra information try: Filter for only built-in Aliases (They have the ReadOnly property) #PowerShell Alias Example Note 1: To list only the DOS and UNIX commands change -match to -notMatch Note 2: 'Where' is an alias for the cmdlet
'where-Object'. Check for more 'object' aliases with:
Guy
Recommends: WMI Monitor and It's Free!
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Alias | Definition | Alias | Definition | |
| % | foreach-object | ipal | import-alias | |
| ? | where-object | ipcsv | import-csv | |
| ac | add-content | kill | stop-process | |
| cat | Get-content | lp | out-printer | |
| cd | set-location | ls | Get-Childitem | |
| chdir | set-location | mi | move-Item | |
| clc | clear-content | mount | new-drive | |
| clear | clear-host | move | move-Item | |
| cli | clear-Item | mp | move-property | |
| clp | clear-property | mv | move-Item | |
| cls | clear-host | nal | new-alias | |
| clv | clear-variable | ndr | new-drive | |
| copy | copy-Item | ni | new-Item | |
| cp | copy-Item | nv | new-variable | |
| cpi | copy-Item | oh | out-host | |
| cpp | copy-property | popd | pop-location | |
| cvpa | convert-path | ps | Get-Process | |
| del | remove-Item | pushd | push-location | |
| dir | Get-Childitem | pwd | Get-location | |
| echo | write-object | r | invoke-history | |
| epal | export-alias | rd | remove-Item | |
| epcsv | export-csv | rdr | remove-drive | |
| erase | remove-Item | ren | rename-Item | |
| fc | format-custom | ri | remove-Item | |
| fl | format-list | rm | remove-Item | |
| foreach | foreach-object | rmdir | remove-Item | |
| ft | format-Table | rni | rename-Item | |
| fw | format-wide | rnp | rename-property | |
| gal | Get-alias | rp | remove-property | |
| gc | Get-content | rv | remove-variable | |
| gci | Get-Childitem | rvpa | resolve-path | |
| gcm | Get-command | sal | set-alias | |
| gdr | Get-psdrive | sasv | start-Service | |
| ghy | Get-history | sc | set-content | |
| gi | Get-Item | select | select-object | |
| gl | Get-location | set | set-variable | |
| gm | Get-Member | si | set-Item | |
| gp | Get-property | sl | set-location | |
| gps | Get-Process | sleep | start-sleep | |
| group | group-Object | sort | sort-Object | |
| gsv | Get-Service | sp | set-property | |
| gu | Get-unique | spps | stop-process | |
| gv | Get-variable | spsv | stop-Service | |
| h | Get-history | sv | set-variable | |
| history | Get-history | type | Get-content | |
| icm | invoke-command | where | where-object | |
| ihy | invoke-history | |||
| ii | invoke-Item | |||
| ilal | initialize-alias |

Solarwinds' Orion performance monitor will help you discover what's happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.
Perhaps the NPM's best feature is the way it suggests solutions to network problems. Its second best feature is the ability to monitor the health of individual VMWare virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you take advantage of Solarwinds' offer.
Download a free trial of the Network Performance Monitor.
The command to add your own PowerShell alias is: set-alias. You follow this command with your choice of aliasname and then complete the instruction by specifying an existing PowerShell verb-noun, for example:
# PowerShell create alias
Clear-Host
new-alias xcopy copy-Item
# or
Set-Alias xcopy copy-Item # works just as well
The new alias is called xcopy and what it does is the equivalent of copy-Item. To double check type: Get-alias xcopy
N.B. Don't go mad with aliases, stick to one verb and one noun. I tried this:
set-alias eventvwr
Get-Eventlog application, however it did not work as I had hoped - too many arguments.
set-alias
eventvwr is ok, but rather disappointing because it prompts you for the name of the log.
Function - An alternative to Alias
If you really need a more complex set of commands then consider creating a
function, which you can then save to the Function 'drive', investigate with:
Get-psdrive or Get-psdrive function.
Sequencing - Aliases come first
Suppose you have an Alias called
'eventvwr' and also a cmdlet with the same name
'eventvwr.ps1', but with different instructions. What would happen is the Alias would be processed first. In fact PowerShell checks the Aliases before it looks for functions or cmdlets.
If you just create an alias at the command prompt it is desperately disappointing that PowerShell does not remember your aliases the next time you logon. Good news, you can add your aliases to profile.ps1, the benefit is they will now be available for each and every session.
My friend 'Barking' Eddie even has a file just for his aliases, he calls it profile_alias.ps1. His trick is to call this dedicated file from within profile.ps1 with this line:
."C:\ Documents and Settings\EDDIE\My Documents\PSConfiguration\profile_alias.ps1"
If you try this at home, then
substitute your username for EDDIE, or else it will not work.
N.B. That's not dirt on the screen or a Guy error, there really is a full stop or 'period' in front of ."C: \ ".
Some say Eddie is Barking mad, but actually he is from Barking in Essex, either way, he takes this linking idea further and creates a profile_function.ps1 file for his special functions.
Aliases in cmdlets?
Can you call an Alias from a cmdlet? The answer is yes, why ever not, remember that cmdlets mimic keystrokes you type at in the Microsoft Shell.

Import users from a spreadsheet. Just provide a list of the users with their fields in the top row, and save as .csv file. Then launch this FREE utility and match your fields with AD's attributes, click to import the users. Optionally, you can provide the name of the OU where the new accounts will be born.
There are also two bonus tools in this free download, and all 3 have been approved by Microsoft:
Download your FREE bulk import tool.
My old friend 'Barking' Eddie has produced some great PowerShell scripts and at present they work fine. However, Eddie has created a time bomb, the problem is that his cmdlets have so many bizarre aliases that no-one else can understand them. Eddie has no scruples, he is hoping that the people who employ him today, will pay him big bucks to come out of his retirement and fix those cmdlets that no-one else can decipher.
The lesson is this, if you only have yourself to please, then create all the aliases that you want. However, if others need to understand or troubleshoot your scripts, then filling them with aliases will only store up problems, which will return to haunt you.
As far as I can see, using a PowerShell Alias has these three benefits:
If you like this page then please share it with your friends
• PowerShell Tutorials • Introduction • Vista PowerShell • Windows 7 PowerShell 2.0
• PowerShell Parameters • -Online • PowerShell Alias • 3 Key Commands
• Cmdlet scripts • Windows PowerShell • PowerShell $_ Variable
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.

You get 36 topics organized into these 3 sections:
1) Getting Started
2) Real-life tasks
3) Examples of Syntax.
In addition to the ebook, you get a PDF version of this Introduction to PowerShell ebook It runs to 120 pages of A4.
*
Custom Search
|
Guy Recommends: WMI Monitor and It's Free!
|
|
Home Copyright © 1999-2012 Computer Performance LTD All rights reserved Please report a broken link, or an error. | |