TechRepublic recently asked members to submit their favorite Network Administration scripts for possible publication. One of the first to make a submission was Tim Wakeling. For his effort, Tim earned $100 and the satisfaction of seeing his script published on TechRepublic.


Earn $100 for your admin script


Let us pay you for your original scripts so that we can publish them as downloads on TechRepublic and allow your fellow IT professionals to benefit from your scripting savvy. We only ask that you put in the appropriate comments to your scripts so that it's easy to tell what the script is doing and which variables might need to be customized. Send us your original admin scripts and we'll pay you $100 for each one that we publish as a TechRepublic download.


In their own words

I pulled this out of my login script. I have it group based which is why I have a call to the Lotus sub routine. What the script does is copy over the user's Notes directory for Lotus Notes from their home drive and copy it to the local PC. Once all the files have been copied over, only a few files are going to change. The logon script (Listing A) will check to see if newer files exist on their home drive, while the logoff script (Listing B) checks for newer files on the local drive and copies them to the network.

Listing A


'------------------------------------------------------------
'Logon Script
'Created June 14, 2005 by Tim Wakeling
'------------------------------------------------------------

Set WshNetwork = CreateObject("WScript.Network") Set ADSysInfo = CreateObject("ADSystemInfo") Set fso = WScript.CreateObject("Scripting.fileSystemObject")

call lotusnotes

Sub LotusNotes()
   dim lotsrc,lotdest,localpath,remotepath
   localpath = "c:\lotus\" & wshnetwork.UserName
   remotepath = "\\bahfp\users\" & wshnetwork.UserName & "\notes"

   'Check to see if Lotus Notes Directories exist
   If (fso.FolderExists("c:\lotus\" & wshnetwork.UserName)) and (fso.FolderExists("\\bahfp\users\" & wshnetwork.UserName))  Then
      'Copy the selected files, but first check to see which version is newer
      CompareNotes "bookmark.nsf",localpath, remotepath
      CompareNotes "us.dic",localpath, remotepath
      CompareNotes "names.nsf",localpath, remotepath
      CompareNotes "user.id",localpath, remotepath
   else
      'If the local directory doesn't exist, copy entire directory over.
      fso.CopyFolderremotepath, localpath
   end if
End Sub


'This function will copy the filename passed from above and will verify the files exist to prevent any errors Sub CompareNotes(filename, localpath, remotepath)
   dim localfile, remotefile
   localfile = localpath & "\" & filename
   remotefile = remotepath & "\" & filename

   'Check to see that Files exist on local and remote
   If (fso.FileExists(localfile)) and (fso.FileExists(remotefile))  Then
      Set localdrive = fso.GetFile(localfile)
      Set remotedrive = fso.GetFile(remotefile)

      'Compare local and remote drive, if remote is newer, then copy to local drive
      if localdrive.datecreated > remotedrive.datecreated then
         fso.CopyFileremotefile, localfile
      end if

   'If file doesn't exist on local PC, then copy from remote
   elseif (fso.FileExists(remotefile)) Then
      fso.CopyFileremotefile, localfile

   'If none of the above conditions exist there is something else wrong.
Call IS and have them look at it.
   else
      wscript.echo("Please call ext. 8195  There is a problem with your Lotus Notes.  BAH Lotus Error:" & filename)
   end if

End Sub


wscript.quit

Here is the logoff script.

Listing B


'------------------------------------------------------------
'Logoff Script
'Created June 14, 2005 by Tim Wakeling
'------------------------------------------------------------


Set fso = WScript.CreateObject("Scripting.fileSystemObject")
Set WshNetwork = CreateObject("WScript.Network")

'Supress All errors
On Error Resume Next

' Gater AD info on user
Set ADSysInfo = CreateObject("ADSystemInfo") Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName) strGroups = LCase(CurrentUser.MemberOf) if strGroups = "" then
   strGroups = LCase(Join(CurrentUser.MemberOf)) end if

' If user is part of Lotus Notes Group then run script If InStr(strGroups, "cn=grp lotus notes") Then
   call lotusnotes
End If

Sub LotusNotes()
dim localfile, remotefile, localpath, remotepath

localpath = "c:\lotus\" & wshnetwork.UserNameremotepath = "\\bahfp\users\" & wshnetwork.UserName & "\notes"
localfile = localpath & "\" & filename
remotefile = remotepath & "\" & filename

  'Copy the selected files, but first check to see which version is newer
   If (fso.FolderExists("c:\lotus\" & wshnetwork.UserName)) and (fso.FolderExists("\\bahfp\users\" & wshnetwork.UserName))  Then
      CompareNotes "bookmark.nsf",localpath, remotepath
      CompareNotes "us.dic",localpath, remotepath
      CompareNotes "names.nsf",localpath, remotepath
      CompareNotes "user.id",localpath, remotepath
   end if
End Sub

'This function will copy the filename passed from above and will verify the files exist to prevent any errors Sub CompareNotes(filename, localpath, remotepath)
   dim localfile, remotefile
   localfile = localpath & "\" & filename
   remotefile = remotepath & "\" & filename

   'Check to see that Files exist on local and remote
   If (fso.FileExists(localfile)) and (fso.FileExists(remotefile))  Then
      Set localdrive = fso.GetFile(localfile)
      Set remotedrive = fso.GetFile(remotefile)

      'Compare local and remote drive, if remote is newer, then copy to local drive
      if localdrive.datecreated < remotedrive.datecreated then
         fso.CopyFilelocalfile, remotefile
      end if

   'If file doesn't exist on local PC, then copy from remote
   elseif (fso.FileExists(remotefile)) Then
      fso.CopyFileremotefile, localfile

   'If none of the above conditions exist there is something else wrong.
Call IS and have them look at it.
   else
      wscript.echo("Please call ext. 8195  There is a problem with your Lotus Notes.  BAH Lotus Error:" & filename)
   end if