Using Perl for Active Directory Scripts

If you are not familiar with using Perl Scripts, its time to learn a little bit more.

My first four posts...

Search Active Directory from Perl Using ADO
Enumerate tokenGroups using Perl
Read OCS Meeting Policy
Find an SPN in Active Directory using Perl

...may seem to be all over the map, but they have two obvious things in common, all of them are written in Perl, and all of them use the same ADODB search code to find the user accounts to work on. I'll discuss the ADODB search code in more detail later, but I wanted to stop and pontificate about Perl for a moment.

Perl rocks. I started scripting with Perl when VBScript was not yet widely used, and never made the switch. Perl is very powerful and well worth the learning curve. Get the latest version of Perl for Windows from ActiveState and here's a link to the famous tutorial by Robert Pepper that I read to get started. For those who want a brainier read, check out the "Camel" book listed in the sidebar.

With respect to Windows, ActiveState's Perl comes with a few modules that provide most of the Windows functionality that you'll typically use, namely Win32::OLE and Win32::TieRegistry. Win32::OLE provides access to the COM libraries on your Windows machine, including ADODB, ADSI, WMI, etc.

Most of the Windows scripting examples out on the Internet are written in VBScript, and so it pays to learn how to translate VBScript syntax into Perl syntax. That's surprisingly not that hard to do. For example, in VBScript, a line like var = object.property is written in Perl as $var = $object->{property} no big deal. Besides slightly different syntax, the techniques and constructs are largely the same across the languages. When I see an example on the web, I generally don't care if it's in another language, I can generally learn what the important part of the code is doing, and translate it into the language that I want to use.

Perl's certainly not perfect for everything. For one thing, it can't use the .Net libraries, and it's not good for anything graphical, so I use Visual Studio languages in those cases. I'll post some of that code as well.


0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...