Hey, Scripting Guy! Quick-Hits Friday: The Scripting Guys Respond to a Bunch of Questions (6/5/09)
How Can I Create Unique User Permissions on Windows Server 2003 with Group Policy?
Hey, Scripting Guy! We are using Windows Server 2003 R2. I want to create a Group Policy policy setting for individual users according to their permission on folders. Currently, we are just using a folder share to all users. We have almost 40 users and approximately 100 folders on our server, but the problem is we cannot define more than 15 or 20 folders for a single user because the folders must be changed upon completion of any project. So I need your help with Group Policy scripting on Windows Server 2003 that uses unique user permissions.
– TM


Hi TM,
You cannot script the creation of Group Policy objects directly by using scripting, unless you have a third-party software package. In Windows 2008 R2, there are Windows PowerShell cmdlets that let you work with Group Policy. However, that product is still in beta.
However, it seems to me that Group Policy might not be the best way to go. I think if it were I, I would create several user groups and include the appropriate users in the groups. I would then use NTFS Security permissions on the individual folders, and assign the permission to the folder to the Active Directory Groups.
Scripting the creation of froups and the modification of froups is a challenge well within your means. We have hundreds of scripts in the Script Repository that explain scripting users and groups in Active Directory. We also have dozens of “Hey, Scripting Guy!” articles talking about user management from a scripting perspective. But the single place you have to visit for information about scripting Active Directory is the Script Center Active Directory Hub. As soon as you have created the groups and assigned the users to the groups, you could then use a command-line tool such as Icacls.exe which is included in Windows Server 2003 R2 to change the NTFS permissions.
How Can I Format Specific Words in a Word Document?
Hey, Scripting Guy! You asked for it in a “Hey, Scripting Guy!” article. I am a staffing person, and I am just slightly techie. My goal is to present a better-looking resume of candidates to hiring managers with keywords and phrases from the job descriptions.
– JP


Hi JP,
In the “Hey, Scripting Guy!” article, How Can I Boldface a Specific Word Throughout a Microsoft Word Document?, we talk about making a specific word bold in a Microsoft Word document. This MSDN article details the Font object from the Microsoft Word Automation model. In particular, the two properties that you have to work with, the Bold and the Italic properties, are shown here:
objSelection.Find.Replacement.Font.Bold = TrueobjSelection.Find.Replacement.Font.Italic = True
Here is a script I wrote that shows how you may actually use this. Be aware the wscript.echo command will produce a pop-up dialog box for each file, if you double-click the script to start it. What you have to do is run it by using the command prompt using cscript. In this script, we have an array that holds the file names. You would have to use the FileSystemObject to read the folder and return a collection of files. You just have to use the getFolder method and the files command. This article may help update your memory on the technique of working with files and folders. Here is the OpenResumeMarkWords.vbs script.
OpenResumeMarkWords.vbs
‘========================================================================== ‘ ‘ NAME: OpenResumeMarkWords.vbs ‘ ‘ AUTHOR: ed wilson , msft ‘ DATE : 3/25/2009 ‘ ‘ COMMENT: Opens a series of resumes, and Bold faces and Italics key words ‘ in the document. It then saves the changes and exits. ‘ http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb06/hey0201.mspx ‘ http://www.microsoft.com/technet/scriptcenter/resources/qanda/mar06/hey0321.mspx ‘ http://www.microsoft.com/technet/scriptcenter/resources/officetips/may05/tips0512.mspx ‘ http://msdn.microsoft.com/en-us/library/bb211946.aspx ‘==========================================================================Const wdReplaceAll = 2 Set objWord = CreateObject(“Word.Application”) objWord.Visible = False
arrFiles = Array(“C:\fso\Resume1.doc”,”C:\fso\Resume2.doc”) For Each sFile In arrFiles WScript.Echo “Checking ” & sFile & ” for keywords” Set objDoc = objWord.Documents.Open(sFile) Set objSelection = objWord.Selection arrWords = Array(“Exchange”, “Windows Server”, “MCSE”) For Each strWord in arrWords objSelection.Find.Text = strWord objSelection.Find.Forward = True objSelection.Find.MatchWholeWord = True objSelection.Find.Replacement.Font.Bold = True objSelection.Find.Replacement.Font.Italic = True objSelection.Find.Execute ,,,,,,,,,,wdReplaceAll Next objDoc.Save objDoc.Close Next objWord.quit
How Can I Find Drive Free Space for Volumes on Volume Mount Points?

Hey, Scripting Guy! Every month we run a VBScript program to collect drive free space from some of our servers. This works fine for conventional volumes with drive letters. Can you show us a VBScript example that will also get the drive free space for volumes on volume mount points?
– GF


Hi GF,
There are two WMI classes that will be useful to you:
- WIN32_volume
- WIN32_MountPoint
Using the Scriptomatic 2.0, you can easily query the first class, WIN32_volume. Be aware that the WIN32_Volume WMI class is installed on Windows Server 2003 and later. It does not exist on Windows XP. The second WMI class, WIN32_MountPoint, is also present on Windows Server 2003 and later. It is an association class. Here is the Managed Object Format (MOF) syntax for the WIN32_MountPoint WMI class.
class Win32_MountPoint{ Win32_Directory ref Directory; WIN32_Volume ref Volume;};
You can see that the WIN32_MountPoint WMI class references a Directory and a Volume. This is exactly the information that you must have in order to be able to document your server. Association classes are a bit bothersome to work with, but here are some examples:
- http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct04/hey1007.mspx
- http://www.microsoft.com/technet/scriptcenter/resources/qanda/jul05/hey0719.mspx
- http://www.microsoft.com/technet/scriptcenter/resources/qanda/jul08/hey0728.mspx
How Can I Determine Which MAC Address Is Associated with a Network Adapter?
Hey, Scripting Guy! How can I identify which MAC address is associated with a particular network adapter on my computer?
– WL


Hi WL,
You can use WMI to get this information. To perform this, you would do something such as this by using VBScript:
GetIPAddressByMacAddress.vbs
‘==========================================================================
‘
‘
‘ NAME: GetIPAddressByMacAddress.vbs
‘
‘ AUTHOR: ed wilson , msft
‘ DATE : 3/18/2009
‘
‘ COMMENT: uses win32_networkadapterconfiguration wmi class to get the
‘ IP address by filtering on the MAC address.
‘==========================================================================
WMIQuery = “Select * from WIN32_networkadapterConfiguration where MacAddress = ’00:00:00:00:00:00′”
Set objWmi = GetObject(“Winmgmts:”)
Set colItems = objWmi.execquery(wmiQuery)
For Each item In colItems
If IsArray(item.IPaddress) Then
For Each ip In item.ipaddress
WScript.Echo ip
Next
ElseIf Not IsNull(item.IPAddress) Then
WScript.Echo item.IPaddress
End If
Next
You can do the same thing by using Windows PowerShell:
PS C:\> gwmi win32_networkadapterconfiguration -filter “macaddress = ’00:00:00:00:00:00′”| ` select macaddress, ipaddressMake sure that you change the script to use the appropriate MAC address from your computer.
How Can I Query the Size of a Pagefile Without Changing the Size of the Same Pagefile?
Hey, Scripting Guy! How would you change this script to just query the size of the pagefile without changing the size of the pagefile?
SetPageFileSize.vbs
strComputer = “.” Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)– BCSet colPageFiles = objWMIService.ExecQuery _ (“Select * from Win32_PageFileSetting”)
For Each objPageFile in colPageFiles objPageFile.InitialSize = 300 objPageFile.MaximumSize = 600 objPageFile.Put_ Next


Hi BC,
Change the code inside the For…Each…Next loop. You want to query the properties, not assign new values for the pagefile. In addition, you do not have to write information back to WMI (which is what the objPageFile.Put_ command does). The revised For…Each…Next loop is seen here:
For Each objPageFile in colPageFiles Wscript.echo objPageFile.InitialSize Wscript.echo objPageFile.MaximumSize NextSetPageFileSize.vbs
strComputer = “.” Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)This WMI class, WIN32_PageFileSetting, will not report anything if the pagefile is not manually configured. This means that if the pagefile is set to system managed, it will not return any information. A system managed pagefile is shown here:Set colPageFiles = objWMIService.ExecQuery _ (“Select * from Win32_PageFileSetting”)
For Each objPageFile in colPageFiles Wscript.echo objPageFile.InitialSize Wscript.echo objPageFile.MaximumSize Next

There are several scripts in the Desktop section of the Script Center Script Repository that provide interesting information. You should examine the scripts to see the ones that you might want to use. You may also be interested in the Desktop Management Hub, which provides links to scripting resources related to desktop management from all over the Script Center.
We would also recommend that you spend some time reviewing the resources linked from our Getting Started page. Here you will find links to articles, webcasts, and other valuable sources of information.
You may also be interested in a good book on VBScript that includes many step-by-step exercises and hundreds of sample scripts. An excellent one is the Microsoft Press book, Microsoft VBScript Step by Step, which is written by Scripting Guy Ed Wilson.
Ed Wilson and Craig Liebendorfer, Scripting Guys
0 comments