Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. ' Create HomeDir.vbs, 3:32 PM 1/4/2006
  2. '
  3. ' File purpose: Add home directories for users on \\HOME\USER dfs share
  4. ' Create File with list of users (userlist.txt)
  5. ' Test if user account active
  6. ' Test if Home directory exists
  7. ' If home directory doesn't exist
  8. ' Create Home Directory
  9. ' Apply permissions using CACLS.EXE (v5.1.2600.0 or newer) may need to download from
  10. ' (Microsoft or get from Windows 2003 Resource kit)
  11. ' Set Home directory location in drive letter
  12. ' Get next user until end of file (userlist.txt)
  13. '
  14. ' To create "UserList.txt" file that the program reads execute the following command.
  15. ' DSQUERY USER OU=IS,OU=PDX,DC=corp,DC=edu-resources,DC=com -LIMIT 0 >UserList.txt
  16. ' This creates a DN list with each user in quotes.
  17. On Error Resume Next
  18. Set objFSO = CreateObject("Scripting.FileSystemObject")
  19. 'clear file for next report
  20. Set RepFile = objFso.OpenTextFile("HomeDirReport.txt", 2, True)
  21.  
  22. Const USER_ROOT_UNC = "\\pdx23\home"
  23. Const USER_HOME_UNC = "\\Corp\Home"
  24.  
  25. Set objArgs = WScript.Arguments
  26. Set objFSO = CreateObject("Scripting.FileSystemObject")
  27. Set objTextFile = objFSO.OpenTextFile("userlist.txt", 1) '1 is for reading file only
  28. Set WshShell = Wscript.CreateObject("Wscript.Shell")
  29.  
  30. ' Read file line by line until end is reached
  31. Do While objTextFile.AtEndOfStream <> True
  32. strNextLine = objTextFile.Readline
  33. wscript.echo strNextLine
  34.  
  35. ' Check to see if user account is disabled
  36. ' Remove qoutes from text file
  37. TrimUser = "LDAP://" & replace(strNextLine, chr(34),"") ' Remove qoutes to use GetObject
  38. Set objUser = GetObject(TrimUser)
  39.  
  40. if objuser.AccountDisabled = False then ' True when Account Disabled is False
  41. WScript.Echo "The account is enabled."
  42. HomeDir = objuser.SamAccountName
  43. ' Use mailNickName or SamAccountName, logon name doesn't work
  44.  
  45. ' Does Home directory exist?
  46. if objFSO.FolderExists(USER_ROOT_UNC & "\" & HomeDir) Then
  47. ' Do nothing, directory already exists.
  48. Else
  49. ' Create User directory on \\corp\home\....
  50. Set objFS = CreateObject("Scripting.FileSystemObject")
  51. Call objFS.CreateFolder(USER_HOME_UNC & "\" & HomeDir) ' Create home directory
  52.  
  53. ' Set NTFS permissions on Home directory, use external program xcacls
  54. Call SetUserDirPerm()
  55.  
  56. End If
  57. 'Folder and home entries completed
  58. Else
  59. ' The account is disabled.
  60. End If
  61. ' No more users in file
  62. wrtToFile()
  63. Loop
  64. '
  65. '
  66. ' ' Set NTFS permissions on Home directory, use external program xcacls
  67. Sub SetUserDirPerm()
  68. Call WshShell.Run("Cacls " & USER_ROOT_UNC & "\" & HomeDir & _
  69. " /E /G " & "CORP\" & HomeDir & ":C", Hide_window, Wait_on_Return)
  70. End Sub
  71.  
  72. '
  73. ' Save user information to text file "HomeDirReport.txt"
  74. Sub WrtToFile()
  75. Set RepFile = objFso.OpenTextFile("HomeDirReport.txt", 8, True)
  76. ' Open file for appending, create if needed
  77. RepFile.writeLine
  78. RepFile.writeLine(objuser.SamAccountName & " Disabled:" & objuser.AccountDisabled & _
  79. " "& USER_HOME_UNC & "\" & HomeDir)
  80. RepFile.close
  81. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement