Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Create HomeDir.vbs, 3:32 PM 1/4/2006
- '
- ' File purpose: Add home directories for users on \\HOME\USER dfs share
- ' Create File with list of users (userlist.txt)
- ' Test if user account active
- ' Test if Home directory exists
- ' If home directory doesn't exist
- ' Create Home Directory
- ' Apply permissions using CACLS.EXE (v5.1.2600.0 or newer) may need to download from
- ' (Microsoft or get from Windows 2003 Resource kit)
- ' Set Home directory location in drive letter
- ' Get next user until end of file (userlist.txt)
- '
- ' To create "UserList.txt" file that the program reads execute the following command.
- ' DSQUERY USER OU=IS,OU=PDX,DC=corp,DC=edu-resources,DC=com -LIMIT 0 >UserList.txt
- ' This creates a DN list with each user in quotes.
- On Error Resume Next
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- 'clear file for next report
- Set RepFile = objFso.OpenTextFile("HomeDirReport.txt", 2, True)
- Const USER_ROOT_UNC = "\\pdx23\home"
- Const USER_HOME_UNC = "\\Corp\Home"
- Set objArgs = WScript.Arguments
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Set objTextFile = objFSO.OpenTextFile("userlist.txt", 1) '1 is for reading file only
- Set WshShell = Wscript.CreateObject("Wscript.Shell")
- ' Read file line by line until end is reached
- Do While objTextFile.AtEndOfStream <> True
- strNextLine = objTextFile.Readline
- wscript.echo strNextLine
- ' Check to see if user account is disabled
- ' Remove qoutes from text file
- TrimUser = "LDAP://" & replace(strNextLine, chr(34),"") ' Remove qoutes to use GetObject
- Set objUser = GetObject(TrimUser)
- if objuser.AccountDisabled = False then ' True when Account Disabled is False
- WScript.Echo "The account is enabled."
- HomeDir = objuser.SamAccountName
- ' Use mailNickName or SamAccountName, logon name doesn't work
- ' Does Home directory exist?
- if objFSO.FolderExists(USER_ROOT_UNC & "\" & HomeDir) Then
- ' Do nothing, directory already exists.
- Else
- ' Create User directory on \\corp\home\....
- Set objFS = CreateObject("Scripting.FileSystemObject")
- Call objFS.CreateFolder(USER_HOME_UNC & "\" & HomeDir) ' Create home directory
- ' Set NTFS permissions on Home directory, use external program xcacls
- Call SetUserDirPerm()
- End If
- 'Folder and home entries completed
- Else
- ' The account is disabled.
- End If
- ' No more users in file
- wrtToFile()
- Loop
- '
- '
- ' ' Set NTFS permissions on Home directory, use external program xcacls
- Sub SetUserDirPerm()
- Call WshShell.Run("Cacls " & USER_ROOT_UNC & "\" & HomeDir & _
- " /E /G " & "CORP\" & HomeDir & ":C", Hide_window, Wait_on_Return)
- End Sub
- '
- ' Save user information to text file "HomeDirReport.txt"
- Sub WrtToFile()
- Set RepFile = objFso.OpenTextFile("HomeDirReport.txt", 8, True)
- ' Open file for appending, create if needed
- RepFile.writeLine
- RepFile.writeLine(objuser.SamAccountName & " Disabled:" & objuser.AccountDisabled & _
- " "& USER_HOME_UNC & "\" & HomeDir)
- RepFile.close
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement