More on PowerShell… My first script.

January 2, 2007 on 9:46 am | In .NET Coding |

Ok, in case you missed it, don’t want to read it, in my last post, I’ve been looking at PowerShell now. Since I’ve had so much use for VBScript in the past, and I really like .NET, it seems like a good match.

PowerShell is .NET Based, which is something I like, because I have lately come to think in objects, and it works for me. This may also be a good path for developers to get FROM scripting into .net programming eventually. (Though all of the systems admins who turn into programmers surely leave behind many broken hearts, especially managers’.)

It’s extensible, meaning that with a quick flick of visual studio and a once over of the API documentation, you can write your own .net cmdlets (command-letz) that will allow you to effectively extend the ‘language’. This is all a feature of the dynamic linking style that .NET affords us, so while it’s billed as a new feature of the scripting architecture, it’s really just a sort of modified duck typing that hides .NET’s normal modus operandi not too far under the covers.

You can make Aliases, or shortcuts for the otherwise seemingly longwinded names of commands. I’m not sure I really get the idea behind the ‘must use a verb, must use a noun’ when defining cmdlets, but I suppose if the idea of programming is foreign to you, they can tell you any rules they want and that’ll be ok with you.

REALLY cool feature number one: They’ve unified the concept of browsing a filesystem with browsing a ’something’. In this case the ’something’ can be (out-of-the-box) a registry hive or a filesystem. Very handy.

REALLY cool feature number two: ADSI and WMI have integrated syntax. Just prefix your objects instantiation with either and you magically have a data source seemingly out of thin air.

I also like the structure of the code. It’s block-scope-oriented like any of our ALGOL descendant friends like C, C++, C#, and Java, but duck typed like our other languages Python and Ruby (or variants in vb-like languages)

I was playing with the bit, just for fun, and here’s what I have:


function UserInfo($name)
{
   $user = [ADSI]"WinNT://DOMAIN/$name,user"
   $user.FullName
   $user.Description
   Write-Host ("Bad Passwords: " + $user.BadPasswordAttempts)
}
$n = Read-Host -prompt "User Name?"
UserInfo($n)

You’ll see that the variables aren’t declared before they’re used, and the types aren’t specified. You also can see that accessing the ADSI WinNT provider (which appears to be named after a bad, old, joke) is as simple as a set of bar brackets and a quoted path. This is just my first little test bit here, but things are going to hopefully move on pretty quick.

The next topic I want to investigate is the enterprise deployment of the powershell runtime. I’m guessing, and this is just a guess, that since the intention was to originally have PowerShell as a default component of the Vista OS that this topic will have already been given much attention by the folks at Microsoft.

No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds. Valid XHTML and CSS. ^Top^