Extracting parameters from a file using regular expressions can be a very effective and practical way of doing things. Suppose, for instance, that you need a logon script that maps drives depending on the computer's sites. A custom parameter file could look like this:
Site1.MapDrive_X=\\server1\share1
Site1.MapDrive_Y=\\server1\share2
Site2.MapDrive_X=\\server3\share1
Site3.MapDrive_Z=\\server4\share4
Extracting those parameters would be as easy as getting the actual site name, building a regular expression, and looping on found matches. Assuming that you've got a
ParameterFileContent variable already available, you'd have something like this:
set oRegExp = new RegExp
oRegExp.Global = True 'To get all matches
oRegExp.IgnoreCase = True 'We don't want to bother with case in our parameter file
'Mapping drives for the current ActiveDirectory site
Set oAdSysInfo = CreateObject("ADSystemInfo")
oRegExp.Pattern = oAdSysInfo.SiteName & "\.MapDrive_(\w)=(.*)"
Set oMatchCol = oRegExp.Execute(ParameterFileContent)
For Each oMatch In oMatchCol '
DriveName = oMatch.SubMatches(0) 'The \w from the first set of parenthesis
SharePath = oMatch.SubMatches(1) 'The .* from the second set of parenthesis
WScript.Echo("DriveName=" & DriveName & " SharePath=" & SharePath)
WshNetwork.MapNetworkDrive DriveName & ":",SharePath,False
Next
Reuse the oRegExp object to process any other needed parameter...
GroupName2.RunApplication=\\server1\share1\Application1\Application1.exe
GroupName2.MapNetworkDrive_X=\\server1\share1
Site1.SQLServerName=SQL01