Date created: Friday, March 26, 2010 9:40:59 PM. Last modified: Thursday, December 13, 2012 11:41:20 AM

File Distribution per Department

This is a script I wrote to distribute FireFox preferences per department but can be modified to distribute any file on a per department basis.

This script reads the current user's department from AD and then grabs their department's FireFox preferences file from a server share so FireFox settings (such as home page) can be set per department (for example, that departments web site) seeing as FireFox isn't supported by GroupPolicy (obviously!) and there are a few ADMs floating around the web but I find it easier to set up FireFox how you want it then copy the prefs file to a server and dish it out, after all its plain text so it makes for easy editing;

'
' This script is used to pull the department in which this user is stored from Active Directory
' and then get the firefox settings for that department of users,
' by copying them from the network share of the same name! Ce' magnifique, jwbensley [at] gmail [dot] com
'---------------------------------------------------------------------------------------------------

Option Explicit 'Require all variables to be defined
dim strShare ' This is the network share where our firefox preferences are located in folders for each OU in active directory
dim WshShell ' Create a variable which will become an object (Windows shell scripting object reference) when defined later
dim objEnv ' Create a variable which will become an object (a windows environment object reference) when defined later
dim fs ' Create a variable to store the FileSystem output
dim objADSysInfo ' Create a variable which will become an object (an active directory system info object reference) when defined later
dim strUser ' Create a variable to store the current username
dim objUser ' Create a variable which will become an object (an object to contain the user record) when defined later
dim strDepart ' Create a variable to store the current users department

On Error Resume Next ' Safety first you know!

' Create a WshShell object
Set WshShell = CreateObject("WScript.Shell")

' Call the environment scripting reference
Set objEnv = WshShell.Environment("Process")

' Declare a string to store the network share where all the good stuff is stored
strShare = "\\server\Distribution\Firefox\"

' Set our FileSystem varibale to hold the FileSystem scripting object
Set fs = CreateObject("Scripting.FileSystemObject")

' Create an Active Directory system info object reference
Set objADSysInfo = CreateObject("ADSystemInfo")

' Grab the current username
strUser = objADSysInfo.UserName

' Create an object that contains the user object stored in active directory
Set objUser = GetObject("LDAP://" & strUser)

' Grab the current users department from their returned AD info
strDepart = objUser.department

' Call our folder contents sub and pass the contents of the %APPDATA% variable and add the remainder on to reach the firefox Profiles folder
Call ListFolderContents(objEnv("APPDATA") & "\Mozilla\Firefox\Profiles", strDepart)

' When the code returns here after calling the above sub rountine and running through it, we should empty out our FileSystem variable of the FileSystem object
Set fs = Nothing

' This sub is used to traverse only ONE subdirectory and grab the contents
Sub ListFolderContents(strPath, strDep)

	'On Error Resume Next ' Safety first you know!
	dim folder ' Create folder variable to store folder listings
	dim item ' Create a variable to store each item (sub folder path) for the folder variable

	set folder = fs.GetFolder(strPath)

	For each item in folder.SubFolders
		
		' Copy the firefox preferences file from the server to the destination folder
		fs.CopyFIle "\\server\Distribution\Firefox\" & strDep & "\prefs.js", item.Path & "\", True

	Next

	set folder = Nothing

' End the sub
End Sub

Previous page: Empty Recycling Bin
Next page: File Reporter