Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Script to Copy Word Normal.Dotm File

Posted on 2014-09-19
3
164 Views
Last Modified: 2015-01-17
Hi I am having an issue, I need to create a script to rename (some users have macros don't want to delete)  the existing copy of Word's Normal.dotm file and copy a new one from a network share. The problem is I need the script to copy one normal file to a specific group, then copy a different normal to everyone else in an AD environment.



I tried using a batch file through sccm doesn't work, tried using file copy through GPO and it doesn't work as well. Thanks experts in advance for your help.
0
Comment
Question by:jaya31
  • 2
3 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 40335939
Hi, as an example,
Here is what I use to copy a newer normal.dotm from a server share.
It checks whether the user template on N drive is older than the server copy, will backup up the user copy, then copy over the new version.

Regards,

Rob.

If objFSO.FileExists("\\server\apps\Template\Normal.dotm.new") = True Then
	If CDate(objFSO.GetFile("\\server\apps\Template\Normal.dotm.new").DateLastModified) > CDate(objFSO.GetFile("N:\Normal.dotm").DateLastModified) Then
		intBkpNum = 1
		While objFSO.FileExists("N:\Normal.dotm_bak" & intBkpNum) = True
			intBkpNum = intBkpNum + 1
		Wend
		objFSO.MoveFile "N:\Normal.dotm", "N:\Normal.dotm_bak" & intBkpNum
		objFSO.CopyFile "\\server\apps\Template\Normal.dotm.new", "N:\Normal.dotm"
	End If
End If

Open in new window

0
 

Author Comment

by:jaya31
ID: 40342916
Thank you for you response. This is actually what I am looking for, but I need to do it based on groups in AD\GPO. We have one department that needs  a specific normal while other departments require another. Is there any way to do that
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 40345262
Hi, sorry for my delay. I have been quite busy.  This script will now check for the group membership, and set a different Normal template for each group.

Regards,

Rob.

' THIS LINE MUST BE PLACED IN THE MAIN CODE TO ALLOW THE DICTIONARY
' OBJECT TO REMAIN PERSISTENT FOR THE ISMEMBEROFGROUP FUNCTION
Dim objMemberships

Set objADSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)

If IsMemberOfGroup(objUser, "Group 1") = True Then
	strNormal = "\\server\apps\Template\NormalGroup1.dotm.new"
Else
	strNormal = "\\server\apps\Template\NormalGroup2.dotm.new"
End If
If objFSO.FileExists() = True Then
	If CDate(objFSO.GetFile(strNormal).DateLastModified) > CDate(objFSO.GetFile("N:\Normal.dotm").DateLastModified) Then
		intBkpNum = 1
		While objFSO.FileExists("N:\Normal.dotm_bak" & intBkpNum) = True
			intBkpNum = intBkpNum + 1
		Wend
		objFSO.MoveFile "N:\Normal.dotm", "N:\Normal.dotm_bak" & intBkpNum
		objFSO.CopyFile strNormal, "N:\Normal.dotm"
	End If
End If

Function IsMemberOfGroup(objADUser, strGroupCN)
	If IsEmpty(objMemberships) = True Then
		Set objMemberships = CreateObject("Scripting.Dictionary")
		objMemberships.Add LCase("ALL"), 0
		If IsNull(objADUser.MemberOf) = False Then
			If TypeName(objADUser.MemberOf) = "String" Then
				objMemberships.Add LCase(Mid(Split(objADUser.MemberOf, ",")(0), 4)), 0
			Else
				For Each strGroupName In objADUser.MemberOf
					objMemberships.Add LCase(Mid(Split(strGroupName, ",")(0), 4)), 0
				Next
			End If
		End If
	End If
	If objMemberships.Exists(LCase(strGroupCN)) = True Then
		IsMemberOfGroup = True
	Else
		IsMemberOfGroup = False
	End If
End Function

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question