Solved

Script to Copy Word Normal.Dotm File

Posted on 2014-09-19
3
153 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
issue with beginner powershell script. 5 54
React or Angular? 6 53
Python variable _ manually assigned 9 64
Python 3.5.2 32 virtualenv problems 3 2
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 …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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 …

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now