Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


August 11, 2006

Scripting DFS

Get the specific server-location information you need from Microsoft’s DFS tools
RSS
Subscribe to Windows IT Pro | See More Backup and Recovery Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!
SideBar    DFS Scripting Tools, Arrays and Temporary Files

Download the Code Here

Distributed File System (DFS) is becoming increasingly popular as a way to present users with a link to resources without regard for the actual back-end storage location. As the Microsoft article "How DFS Works" (http://technet2.microsoft.com/WindowsServer/en/Library/a9096e88-1634-4da6-b820-537341d349061033.mspx) explains, DFS lets you create a virtual view of shared folders through a namespace that an administrator creates. Users can view the namespace without needing to know where the data resides, regardless of whether it's on a Windows server or a non-Windows storage device. Because of DFS's increased popularity, I'm getting more frequent questions about how to script configuration and reporting of DFS. Fortunately for script writers, Microsoft provides several command-line tools that you can use to configure and query DFS. (For details about these tools, see the sidebar "DFS Scripting Tools," linked above.) However, these tools can return a lot more information than you really need. For example, most systems administrators and backup operators simply need to know the locations of specific back-end servers so that they can restore accidentally deleted files. To address this need, I wrote the DFSReportBuilder.bat script, a tool that will help you get valid output on the back-end target server locations that your DFS links are really pointing to. Using this script will make it easier for systems administrators and backup operators to locate backups that require restoration.

Listing 1 shows an excerpt from DFSReportBuilder.bat. You can download the complete script by clicking the Download the Code Here button above. I tested this script on a Windows XP Service Pack 2 (SP2) node running in a Windows Server 2003 domain. Always be sure to test your scripts in a development environment before deploying them in a production setting.

Requirements
The basic requirements for the DFSReportBuilder.bat script are that we capture all the DFS links and send an email message containing those links and the back-end server locations that the links map to. The Dfsutil.exe tool offers a switch option, /Export, for exporting the results to a file, but unfortunately, the export mode generates some XML output that isn't useable in the email message. Consequently, DFSReportBuilder.bat instead uses the /View option to capture and filter the output before using the Blat public domain command-line email program to send the report to a recipient list. The report format that we want the script to produce will contain only header information, the date of the report, and the DFS root name. Each line in the report will include the root name, link name, and target-server locations. If a link has more than one target-server location, the additional locations will appear on subsequent report lines. Although the Dfsutil.exe tool output contains the information we need, the output will require some massaging to yield the specific information we want for the email report. Let's look at four simple steps that will help you think through data filtering.

Step 1: Identify Important and Trivial Information
The first step in determining how to filter command output is to identify the information you need. I generally start by redirecting the command from my chosen tool (in this case, Dfsutil.exe) to a text file by using syntax such as:

DFSutil.exe /Root:\\Sales\ 
  Reports /View>C:\DFS.txt 

An examination of the output reveals a series of entries that include a line containing the link name and one or more lines with the target server or servers that are the back-end location of the data. Also, the output includes a line that gives us the DFS root name.

Step 2: Determine Your Filtering Execution Strategy
There are two basic ways to handle filtering. One way is to process the command output one line at a time, getting it into the format you need as it's coming from a file or For command. The second way is to use a batch technique in which you capture some or all of the command output in an array or file and process it all at once.

For this article's example, we'll first use a temporary file to hold the original output, as the sidebar "Arrays and Temporary Files," explains. Then, in the DFSReportBuilder.bat script, we'll use a two-stage filter. First, we'll use the batch strategy, as the code at callout C in Listing 1 shows. Second, we'll use the single-line approach, as the code at callout D shows.

   Previous  [1]  2  Next 


Reader Comments

You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
Accessing Database Data with ADO

...

The Memory-Optimization Hoax

Don't believe the hype. At best, RAM optimizers have no effect. At worst, they seriously degrade performance. ...

Friday at PASS Europe 2006

Kevin talks about the closing day of the event and shares a funny Microsoft film. ...


Related Events Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.

Job Openings in IT


ADS BY GOOGLE SPONSORED LINKS FEATURED LINKS

Maximize your SharePoint Investment – 8 Cities
Discover best practices and tips for both architecting and administering SharePoint. Early Bird Price of $99 through Sept 15th.

Find a new job now on the all new IT Job Hound!
Search jobs, post your resume, and set up job e-mail alerts!

Master SharePoint with 3 eLearning Seminars
Learn how to build a better SharePoint infrastructure and enable powerful collaboration with MVPs Dan Holme and Michael Noel. Register today!

Top Tools for Virtualization Disaster Recovery & Replication
View this web seminar on August 14th to learn about two tools that will result in faster backup and restore with P2V disaster recovery.

SharePointConnections Conference Fall 2008
Don’t miss the premier event for Microsoft IT Professionals in Las Vegas, November 10-13. Register and book your room by August 25 and receive a FREE room night (based on a three night minimum stay).

VMworld 2008 - Sign Up Today!
Join your peers on September 15-18 at The Venetian Hotel in Las Vegas as VMware hosts VMworld 2008, the leading Virtualization event.



Increase Application Performance
Free White Paper by Editor's Best winner, Texas Memory Systems.

Microsoft® Tech•Ed EMEA 2008 IT Professionals
Advance your thinking with new ideas and practical real-world solutions at Microsoft’s FIVE day technical infrastructure conference 3-7 Nov., 2008. Register before 26 September 2008 to save €300.

Order Your SQL Fundamentals CD Today!
Learn how to use SQL Server, understand Office integration techniques and dive into the essentials of SQL Express and Visual Basic with this free SQL Fundamentals CD.

Are You Really Compliant with Software Regulations?
View this web seminar that will help you with compliance best practices and check out a management solution to assure that you won’t be in jeopardy of an audit.

Virtualization Congress Oct. 14-16 in London
Don't miss Virtualization Congress, the premiere EMEA conference dedicated to hardware, OS and application virtualization. Oct. 14-16.
Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technical Resources Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing