Scripting Central--Scripts and Code Snippets Wanted--April 7, 2006
If you use ADsPaths in your scripts, you’ll want to check out this month’s “Mighty Mini” contest winner. Plus, learn how you can help make Windows Scripting Solutions’ "Snippets to Go" and "Reader to Reader" columns bigger and better.
April 4, 2006
1. Perspectives
I Want YOU!
2. This & That
Isn't It Nice?
Last Chance to Enter the "Mighty Mini" Contest
3. Script Watch
Just the FAQs
The Six Degrees of Kevin Bacon in Exchange Migration
4. Scripter's Toolkit
Get ADsPaths with the Click of a Button
5. Featured White Paper
Exchange Backup and Recovery on an HP BladeSystem
6. Announcements
Save 44% Off the Windows Scripting Solutions Newsletter
Exclusive Spring Savings
7. Events and Resources
Get Closer to Real-Time BI with SQL Server 2005
Top 10 Tips for Upgrading to SQL Server 2005
Special Offer Ends Soon!
Spam Fighting and Email Security for the 21st Century
Secure Your IM Traffic
1. Perspectives
by Karen Bemowski, [email protected]
I Want YOU!
To borrow the popular slogan in the old US Army recruitment posters, I want YOU! No, I'm not trying to build my own personal army, but rather I'm trying to build a collection of scripts and code snippets for the Windows Scripting Solutions (WSS) "Snippets to Go" and "Reader to Reader" columns.
The "Snippets to Go" and "Reader to Reader" columns are popular, so we want to devote more pages to them--which is why I need your help. To make these columns bigger and better, I need you to send me:
Scripts. Have you written a script that has saved you lots of time or perhaps saved the day when an emergency arose? Send it my way.
Reusable code snippets. That's jargon for any functions, subroutines, or other blocks of code you've created to drop into your scripts whenever you need to perform a certain operation. Think of it as "Plug and Play (PnP)" code.
Stories about the experiences you've had while writing your scripts. Have you discovered a helpful freeware utility? Have you come up with a unique scripting technique? Tell me about it.
You don't need to be a WSS subscriber to have your article published in the "Snippets to Go" or "Reader to Reader" column. And you don't need to know how to write a grammatically correct sentence. It doesn't matter how bad your English might be. (Did I hear a sigh of relief?) We have editors who can turn your words into polished prose.
All you need to do is tell me about your script, code snippet, or scripting experience in 1000 words or less. If you're sending a script or code snippet, tell me what the code does, why you wrote it, and how to use it. If you've discovered a helpful freeware utility or developed a unique scripting technique, tell me about your experience. WSS is an "equal opportunity" publisher--we publish articles about code written in just about any scripting language, including VBScript, JScript, Perl, and T-SQL.
You can send your article (or articles if you'd like to send more than one) to me at [email protected]. Please include your full name and telephone number. If your article includes code, please include the code file. When I get your submission, I'll send it to a technical editor, who will review the article for technical accuracy and test the code (if applicable).
If the technical editor accepts your article for publication in WSS, we'll send you a copy of the issue in which your article appears so that you can see your name in print. (Heck, we can even send you two copies in case you want to give one to Mom.) Perhaps more important, you'll also receive $100.
Send me your articles today!
2. This & That
Isn't It Nice?
If you're into scripting for Microsoft Exchange Server or Microsoft SQL Server and you live in Europe (or are lucky enough to have a large travel budget), you might be interested in learning that the Connections conference is coming to Europe. On April 24-27, the Connections Europe conference is being held in Nice, France. This event actually consists of four separate conferences dealing with SQL Server, Exchange, ASP.NET, and Visual Studio. Plus, there are bonus sessions on SharePoint and Windows.
Scripting-related sessions include "Outlook 2007 Configuration Scripting for Administrators" by Sue Mosher, a noted author on Microsoft Outlook, and "An Overview of T-SQL Enhancements in SQL Server 2005" by Itzik Ben-Gan, the T-SQL whiz who writes the "T-SQL Black Belt" column in SQL Server Magazine. (By the way, Itzik wrote a very informative article about when to choose T-SQL and when to choose the .NET Common Language Runtime, or CLR, for SQL Server 2005 jobs. If you've been uncertain about which one to use, check out this article in the April issue of SQL Server Magazine.)
The regular price for the Connections Europe conference is 1450 euros. However, you can get a special rate through Scripting Central. When you buy your first conference registration at 1,100 euros, you can get additional passes at half off. To get this special rate, go to http://www.devconnectionseurope.com/?refer=SCRENL and enter promocode SCRENL.
Last Chance to Enter the "Mighty Mini" Contest
If you've written a script that's short in length but long on results, here's your last chance to enter it into the "Mighty Mini" contest. To enter this contest, send a description of what your script does and how to use it, including how readers can customize it for use in their environment. The script can be written in any scripting language. Please include the script file with your submission. You can email your entry and script to [email protected]. Please include your full name and telephone number.
In all, three "Mighty Mini" contest winners will be chosen (one a month for three months). Each winner will receive $100 and get his or her script published in Scripting Central and in Windows Scripting Solutions. In addition, the three winners will be put into a drawing for another $100.
You can find the winning script for the second month in the "Scripter's Toolkit" section. Look for the third month's winner in the May 5 edition of Scripting Central.
3. Script Watch
Just the FAQs
Although Sgt. Joe Friday on Dragnet had wanted just the facts, as scripters, you probably prefer to have just the FAQs. And Dick Lewis delivers just that in his article "The FAQs About Setting Up Your Shell Scripting Environment" in the May issue of Windows Scripting Solutions. In this article, Dick answers the questions on the minds of novice shell scripters. Learn the answers to FAQs such as
I've heard that .bat files' functionality is limited. Is this statement accurate?
How do I know which commands to use for particular tasks?
I've tried running several commands that I've seen in command shell scripting articles, but I receive error messages. What could be causing the problem?
The Six Degrees of Kevin Bacon in Exchange Migration
Determining which users must be migrated together in an upgrade to Microsoft Exchange Server 2003 is a little like playing the game "Six Degrees of Kevin Bacon," in which you try to link an actor to Kevin Bacon through the other actors they've worked with. For example, Benjamin Bratt was in Red Planet with Carrie-Anne Moss, who was in The Matrix with Laurence Fishburne, who in turn appeared in Mystic River with Kevin Bacon. By transitive association, you can link Benjamin to Kevin in three steps, or degrees.
To build transitive association groups in Exchange, you match the mailboxes in an account's permissions list with the mailbox display names of other accounts. Each person is linked to others by the calendar access that he or she grants: Benjamin grants Carrie-Anne access to his calendar, Carrie-Anne gives Laurence access to her calendar, and Laurence grants Kevin access to his calendar. All these people must be migrated together. If you migrate only Benjamin and Carrie-Anne, Laurence can't access Carrie-Anne's new calendar.
Even in small organizations, determining the relationships between accounts can be daunting. To automate the process, Joseph Neubauer has created the GBPR.vbs script. Learn about this script in his article "Good Migrations" in the May issue of Exchange & Outlook Administrator (http://www.windowsitpro.com/MicrosoftExchangeOutlook/Article/ArticleID/49613/49613.html).
4. Scripter's Toolkit
Editor's note: Jim Turner is the second winner of the "Mighty Mini" contest. His HTML Application (HTA) returns ADsPaths.
Get ADsPaths with the Click of a Button
I created a time-saving utility named GetADsPath, which returns the ADsPaths of Active Directory (AD) objects. When you enter an object's name (CN, sAMAccountName, or GroupName attribute), the utility returns the ADsPath of that object. You can then copy the ADsPath into any code that requires an ADsPath.
For example, let's say you have an object named XPDuplicator and you don't know its ADsPath. With the GetADsPath utility, you simply enter XPDuplicator into the utility's UI and click the "Get AdsPath & OU" button to get an ADsPath such as "LDAP://CN=XPDuplicator,OU=Unique,OU=USAssets,OU=Workstations,OU=All Computers,DC=ad,DC=mycompany,DC=com." You can then copy that ADsPath and paste it into code such as
Set objObject = _ GetObject("LDAP://CN=XPDuplicator,OU=Unique,OU=USAssets," _ & "OU=Workstations,OU=All Computers,DC=ad,DC=mycompany,DC=com")
Besides the ADsPath, the utility returns the organizational unit (OU) an object is in. You should be able to key in any valid AD object and receive an ADsPath. However, not all objects have an OU, so that field might be blank.
You can download the GetADsPath.hta file by going to http://www.windowsitpro.com/Windows/Article/ArticleID/49902/49902.html and clicking the 49902.zip hotlink.) Let's take a quick look at part of the utility's code. When a user enters an AD object's name and clicks the "Get AdsPath & OU" button, the following getADSPathOU subroutine executes:.
Sub GetADSPathOU On Error Resume Next Const ADS_SCOPE_SUBTREE = 2 DNC = GetObject("LDAP://RootDSE").Get("defaultNamingContext") Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCommand.ActiveConnection = objConnection objCommand.Properties("Page Size") = 1 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE If Trim(AD_Obj.Value) = "" Then ADobj = "Administrator" : AD_Obj.Value = "Administrator" Else ADobj=Trim(AD_Obj.Value) End If objCommand.CommandText = "SELECT Adspath FROM 'LDAP://" & _ DNC & "'" & " WHERE name='" & ADobj & "'" & " OR _ sAMAccountName='" & ADobj & "'" Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst If Err 0 Then If Err.Number = 3021 Then TxtADSPath.Value = Trim(AD_Obj.Value) & " Not Found!!!" Else TxtADSPath.Value = Err.Number & " " & Err.Description End If txtou.Value = "" Err.Clear Exit Sub End If arrAD = Split(objRecordSet.Fields("AdsPath").Value, ",") For i = 0 to Ubound(arrAD) If InStr(arrAD(i), "OU=") OR InStr(arrAD(i), "LDAP://OU=") Then iLength = Len(arrAD(i)) leading = iif(InStr(arrAD(i),"LDAP://OU="),10,3) OULength = iLength - leading OU = Right(arrAD(i), OULength) Exit For End If Next txtou.Value = OU TxtADSPath.Value = objRecordSet.Fields("Adspath").Value objRecordSet.MoveNext Msgbox "Done" End Sub
After the subroutine declares its constant, it sets up a variable that will contain the domain's name. This makes the code more generic so that you don't have to hard-code the domain information. The next several lines of code set up the connection to the AD database using ActiveX Data Objects (ADO). The subroutine creates an ADO Connection object to connect to AD, an ADO Command object that will contain the query, and an ADO Recordset object that will contain the resulting records.
The heart of the code is the SQL query that's stored in the Command object's CommandText property. The utility uses that query to search AD for the object that contains the specified name. If an object is found, the utility displays the ADsPath. If an OU exists, it's extracted from the ADsPath and displayed. When there are multiple OUs in an ADsPath, the utility extracts the first OU.
To extract the OU, the utility breaks the ADsPath into an array, using a comma as a delimiter. In some instances, the OU will be in the first element of the array (e.g., LDAP://OU=BranchOffice Users,OU=Domain Users). In other instances, the OU will be the second element of the array (e.g., LDAP://CN=XPDuplicator,OU=Unique). When the OU is in the first array element, there will be 10 characters before the OU's name. When the OU is in the second array element, there will be 3 characters before the OU's name. Thus, the utility uses the IIf (short for Immediate If) function to determine how many characters to skip (i.e., 3 or 10) to get to where the OU name starts. (For information about the IIf function, see the Windows Scripting Solutions article "A VBScript Version of VBA's IIf Function," http://www.windowsitpro.com/Articles/ArticleID/45816/45816.html.)
The GetADsPath utility will work on Windows Server 2003, Windows XP, and Windows 2000 machines. You need to have AD, Windows Script Host (WSH 5.6), and Microsoft Internet Explorer (IE) 4.0 or later.
The GetADsPath utility will save you time because you don't need to search through AD looking for a particular ADsPath. Even if you do know a complete ADsPath, the utility can save you the hassle of typing the long path and possibly avoid problems that might occur because of typos.
—Jim Turner
5. Featured White Paper
Exchange Backup and Recovery on an HP BladeSystem
Protect mission-critical business information stored on your high-availability Exchange systems when you implement backup and restore strategies. You'll also learn about key configuration and deployment considerations.
http://www.windowsitpro.com/go/whitepapers/hp/bladeexchange/?code=0405featnl
6. Announcements
Save 44% off the Windows Scripting Solutions Newsletter
For a limited-time, order the Windows Scripting Solutions newsletter and SAVE up to $80. You'll get 12 helpful issues loaded with expert-reviewed downloadable code and scripting techniques, as well as hundreds of tips on automating repetitive tasks. You'll also get FREE, unlimited access to the full online scripting article library (more than 500 articles). Subscribe now:
https://store.pentontech.com/index.cfm?s=1&promocode=eu2664us
Exclusive Spring Savings
Subscribe to Windows IT Pro and SAVE 58% off! Along with your 12 issues, you'll get FREE access to the entire Windows IT Pro online article archive, which houses more than 9,000 helpful articles. This is a limited-time offer, so order now:
https://store.pentontech.com/index.cfm?s=1&promocode=eu2064uw
7. Events and Resources
Get Closer to Real-Time BI with SQL Server 2005
Learn to incorporate new services found in SQL Server 2005 to create near-real-time BI information without the need for a data warehouse. Live Event: Thursday, April 20
http://www.windowsitpro.com/go/seminars/hitachi/realtimebi/?partnerref=0405emailannc
Top 10 Tips for Upgrading to SQL Server 2005
Learn the 10 essential tips you need to know when upgrading to SQL Server 2005, including new features designed to help ease the process. Live event: Wednesday, April 26
http://www.windowsitpro.com/go/seminars/idera/sqltips/?partnerref=0405emailannc
Special Offer Ends Soon!
Register now for DevConnections Europe, 24-27 April in Nice, France.
http://www.devconnectionseurope.com/?refer=0403emailannc
Spam Fighting and Email Security for the 21st Century
Learn the best ways to manage your email security (and fight spam) using a variety of solutions and tips.
http://www.windowsitpro.com/go/ebooks/ironport/emailsecurity/?code=0405emailannc
Secure Your IM Traffic
Learn to secure your IM traffic--don't let your critical business information be intercepted!
http://www.windowsitpro.com/toolkits/symantec/index.cfm?code=0405emailannc
Contact Us
About Scripting Central -- [email protected]
About product news -- [email protected]
About your subscription -- [email protected]
This email newsletter is brought to you by Windows IT Pro, the leading publication for IT professionals deploying Windows and related technologies. Subscribe today!
https://store.pentontech.com/index.cfm?s=1&promocode=eu205xfb
View the Windows IT Pro Privacy Policy.
http://www.winnetmag.com/aboutus/index.cfm?action=privacy
Windows IT Pro is a division of Penton Media, Inc. 221 East 29th Street, Loveland, CO 80538, Attention: Customer Service Department
Copyright 2006, Penton Media, Inc. All Rights Reserved.
About the Author
You May Also Like