I suspect everyone (at least reading this) is minimally aware of Powershell. The question is how much have you used it, and I mean ‘really used it’? I know I’ve been happily been using JP Software TCC LE (formally 4DOS, then 4NT) for ages, and for those wondering I am a console junkie – not really a great fan of Explorer. As an aside I do wholeheartedly recommend the JP software TCC LE, that definitely gets my thumbs up!
So I’m finally taking the plunge as PowerShell 2.0 is about to come out. Firstly I’ll cover why I’m now making the move rather than before, then will provide some good links to help get your skills up!
Why update now?
Well Powershell has been out for a long time now, but the big differentiator is that it is now coming part of the standard Windows OS release (Windows 2008, Windows 7) rather than being an additional download. For any developer that has to support 3rd party systems (aka systems you dont own) you ideally want to stick to the standard tools installed on the machine rather than having to get a number of pre-requisites. As it is only installed by default on a small section of machines its far from a slam dunk – but once it gets into the OS distribution we can be fairly sure its going to be mainstream and remain supported!
Memory footprint
So on to most commonly cited downside made by memory conscious folks, so lets get that out of the way!
Randomly Performed on my Windows XP (SP3) – these are definitely not exact but should show orders of magnitude.
- Command – Cmd.exe – Mem Usage 2,572Kb, VMSize 2,008Kb
- TCC LE – TCC.exe – Mem Usage 3400Kb, VMSize 2,944Kb
- Powershell 1.0 – Powershell.exe – Mem Usage 25,324, VMSize 22,668Kb
So obviously it is definitely an order of magnitude heavier than historic command shell implementations. There are several reasons for this, the biggest is that the shell uses a plug-in architecture so you can seamlessly add your own ‘cmdlets’ into the shell. Understandably if you start to run cmdlets (and most everything is a cmdlet) your memory foot print starts to go up as they get loaded into the process. For example if you run “PS” to get a list of running processes your memory footprint will change as that module is loaded and executed. So if you are only concerned about memory footprints you should stop reading now – but if you are looking for functionality this is where PowerShell really shines!
Standard Cmd.exe like Navigation
After starting up powershell (“Start/Run/Powershell”) you start with a command like prompt. In my case its:
PS C:\Documents and Settings\csharphacker>
From here you can do the normal things:
- CD – Change Directory
- DIR – Directory listing
- REN – Rename
- DEL/ERASE – Delete
- PUSHD – Push current location to stack
- POPD – Pop last location from stack
- CLS – Clear Screen
- COPY – Copy file
Also notice there is tab completion of file names
, now standardly available – but a killer not to have!
For Unix folks running on Windows there are Unix equivilents
- LS – Directory List
- RM – Remove file
- PWD – Current directory
- PS – Process list
- CAT – Output contents of file
Still pretty standard stuff. As you look closer you will see that infact these are not build-in commands, but actually aliases to other commands within the shell.
CommandType Name Definition
----------- ---- ----------
Alias ac Add-Content
Alias asnp Add-PSSnapin
Alias clc Clear-Content
Alias cli Clear-Item
Alias clp Clear-ItemProperty
Alias clv Clear-Variable
Alias cpi Copy-Item
Alias cpp Copy-ItemProperty
Alias cvpa Convert-Path
Alias diff Compare-Object
Alias epal Export-Alias
Alias epcsv Export-Csv
Alias fc Format-Custom
Alias fl Format-List
Alias foreach ForEach-Object
Alias % ForEach-Object
Alias ft Format-Table
Alias fw Format-Wide
Alias gal Get-Alias
Alias gc Get-Content
Alias gci Get-ChildItem
Alias gcm Get-Command
Alias gdr Get-PSDrive
Alias ghy Get-History
Alias gi Get-Item
Alias gl Get-Location
Alias gm Get-Member
Alias gp Get-ItemProperty
Alias gps Get-Process
Alias group Group-Object
Alias gsv Get-Service
Alias gsnp Get-PSSnapin
Alias gu Get-Unique
Alias gv Get-Variable
Alias gwmi Get-WmiObject
Alias iex Invoke-Expression
Alias ihy Invoke-History
Alias ii Invoke-Item
Alias ipal Import-Alias
Alias ipcsv Import-Csv
Alias mi Move-Item
Alias mp Move-ItemProperty
Alias nal New-Alias
Alias ndr New-PSDrive
Alias ni New-Item
Alias nv New-Variable
Alias oh Out-Host
Alias rdr Remove-PSDrive
Alias ri Remove-Item
Alias rni Rename-Item
Alias rnp Rename-ItemProperty
Alias rp Remove-ItemProperty
Alias rsnp Remove-PSSnapin
Alias rv Remove-Variable
Alias rvpa Resolve-Path
Alias sal Set-Alias
Alias sasv Start-Service
Alias sc Set-Content
Alias select Select-Object
Alias si Set-Item
Alias sl Set-Location
Alias sleep Start-Sleep
Alias sort Sort-Object
Alias sp Set-ItemProperty
Alias spps Stop-Process
Alias spsv Stop-Service
Alias sv Set-Variable
Alias tee Tee-Object
Alias where Where-Object
Alias ? Where-Object
Alias write Write-Output
Alias cat Get-Content
Alias cd Set-Location
Alias clear Clear-Host
Alias cp Copy-Item
Alias h Get-History
Alias history Get-History
Alias kill Stop-Process
Alias lp Out-Printer
Alias ls Get-ChildItem
Alias mount New-PSDrive
Alias mv Move-Item
Alias popd Pop-Location
Alias ps Get-Process
Alias pushd Push-Location
Alias pwd Get-Location
Alias r Invoke-History
Alias rm Remove-Item
Alias rmdir Remove-Item
Alias echo Write-Output
Alias cls Clear-Host
Alias chdir Set-Location
Alias copy Copy-Item
Alias del Remove-Item
Alias dir Get-ChildItem
Alias erase Remove-Item
Alias move Move-Item
Alias rd Remove-Item
Alias ren Rename-Item
Alias set Set-Variable
Alias type Get-Content
So if you start to look at this list you will begin to understand why this is a bigger beast than CMD or TCC LE will ever be. However it has to be said that these commands are not “identical” to your preferred flavor – but more of a likeness to it. So LS doesnt have exactly the same characteristics, the same was that DIR doesn’t either – but the ‘intent is the same’.
The best keyboard shortcut for me is F8 (but I want to remap it to the up arrow!) – read more about shortcuts can be found here.
Recommended Reading Links (I should point out I am not affiliated with any of the below, but they are what I have used to get more acquainted with PowerShell) :
After reading these you should have a better understanding of the power of power shell. If using PowerShell to read/manipulate the registry, open CSV files, perform credential maintenance via script still doesnt make you want to learn it then remember that SQL 2008 has Powershell integration. So now you can browse your SQL schema using PowerShell as well.
This is where we can say for a certainty “Microsoft has started to take scripting seriously”!
Pretty cool stuff,
Gareth