Loving Windows PowerShell

If you've ever lamented the lack of a good command line shell for the Windows environment, you really want to do yourself a favor and download Windows PowerShell right now.

So of course you’ll want to have your environment set up so you can run .Net SDK tools. Robert W. Anderson explains how to get a VS2005 PS command prompt:

Add the following lines to your "$home\My documents\PSConfiguration\Microsoft.PowerShell_profile.ps1"

pushd 'C:\Program Files\Microsoft Visual Studio 8\vc'

cmd /c “mybatchfile.cmd&set” |

foreach {   if ($_ -match “=”) {     $v = $_.split(“=”); set-item -force -path "ENV:\$($v[0])"  -value "$($v[1])"   } }

popd

 

I never really bothered to learn batch/cmd, it always seemed like too much effort for too little return, so as a result I find that the transition from cmd to PowerShell is effortless, everything just works. And on occasion you find something that works a little bit better. Like 'cd' - in PowerShell you can do

PS C:\> cd I:\Documents

PS I:\Documents>

In just one command, instead of the tedious two steps required in cmd.

I'm taking an organic approach to learning the new stuff, as I need to solve a problem, I start looking through the help.

Recently I needed to take a listing of files, filter out some based on name, and get the resulting count and total size on disk. Here’s what I came up with:

$files =$( Get-Content FilestoConvert.txt|ls)

$files = ($files|where {$_.name -notmatch "codepage" -and $_.name -notmatch "Constants"})

$size=0;$files|foreach { $size += $_.length};$size/1024/1024;$files.count

1 Comment

Comments have been disabled for this content.