Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
The primary advantage of using scripts for file system management is the fact that scripts can carry out tasks that would be too tedious and time-consuming to perform using either the graphical user interface or a command-line tool. For example, suppose you have 500 domain controllers, and a new organizational policy requires you to verify the following:
It would take a significant amount of time to carry out this task using Windows Explorer or a command-line tool. By contrast, in about a half hour you can write a script that connects to each domain controller, performs the requisite checks, and logs the data. You can start this script before you go home, and when you return to work the next day, the verification will be complete.
Scripts can be used to carry out tasks such as these because, within the Windows shell, folders are actually COM objects. As COM objects, folders have properties that can be retrieved, properties that answer questions such as:
You can retrieve the properties of any folder in the file system using the Win32_Directory class. The properties available using this class are shown in Table 11.1. To retrieve the properties for a single folder, construct a Windows Query Language (WQL) query for the Win32_Directory class, making sure that you include the name of the folder. For example, this query binds to the folder D:\Archive:
"SELECT * FROM Win32_Directory WHERE Name = 'D:\\Archive'
"
When specifying a file or folder name in a WQL query, be sure you use two backslashes (\\) to separate path components.
Listing 11.1 contains a script that retrieves properties for the folder C:\Scripts. To carry out this task, the script must perform the following steps:
To limit data retrieval to a specified folder, a Where clause is included restricting the returned folders to those where Name equals C:\\Scripts. You must include both backslashes (\\) in the specified name.
Listing 11.1 Retrieving Folder Properties
|
|
Send us your feedback | « Previous | Next » |