Powershell: The little interpreter language that could
Its been a long time since I learned a new technology that constantly interests me to tinker with in my free time.
Powershell, the .NET-based scripting language gives a fresh "scripting" approach to .NET.
Like Bash in unix, it relies heavily upon piping commands in a chain, but the pipe content is not stream-based it is object based, so all of the Powershell commands are polymorphic.
This is an example of a primitive "diff tool" I wrote in 20 clear lines:
Another example: these 6 lines of code display every Type in the CLR (9276 types)
A good crash course (I learned this way) can be found here:
http://blog.slaven.net.au/archives/2007/01/25/powershell-cheat-sheet/
If you havent seen powershell analyzer yet, then go check it out, becore it isnt free anymore!
http://www.powershellanalyzer.com/
Powershell, the .NET-based scripting language gives a fresh "scripting" approach to .NET.
Like Bash in unix, it relies heavily upon piping commands in a chain, but the pipe content is not stream-based it is object based, so all of the Powershell commands are polymorphic.
This is an example of a primitive "diff tool" I wrote in 20 clear lines:
$a = Get-Content c:\test.csv;
$b = Get-Content c:\test.xml;
$long = $a;
$short = $b;
if($b.Length -gt $a.Length) {
$long = $b;
$short = $a;
};
for($line = 1; $line -le $long.Length; $line++){
if($line -le $short.Length -and $short[$line-1] -ne $long[$line-1]){
"line [$line]:"
"one says: [" + $short[$line-1]
"the other says: [" + $long[$line-1]
}
elseif($line -gt $short.Length){
"line [$line]:"
"one says: [" + $long[$line-1]
}
}
Another example: these 6 lines of code display every Type in the CLR (9276 types)
[System.Object].Assembly.GetTypes() | foreach {
$typeCount++
$methodCount += $_.GetMethods().Length
"+--"+$_.Name
}
"Types $typeCount, Methods $methodCount"
A good crash course (I learned this way) can be found here:
http://blog.slaven.net.au/archives/2007/01/25/powershell-cheat-sheet/
If you havent seen powershell analyzer yet, then go check it out, becore it isnt free anymore!
http://www.powershellanalyzer.com/

