VBS -> Auflistung der ADSystemInfo Felder eines Benutzers

    • VBScript (VBS)

      VBS -> Auflistung der ADSystemInfo Felder eines Benutzers

      Hallo Leute,

      der Code dient dazu eine Datei zu erstellen in welcher man immer wieder nachgucken kann
      welcher getter welche User infos holt.

      Nichts besonderes und für die meisten auch nicht interessant, aber eine kleine Fleißaufgabe.


      Hier Code:
      Spoiler anzeigen

      Visual Basic-Quellcode

      1. Dim fso ' FileSystemObject
      2. Dim targetFile ' Path of Textfile containing Script Output
      3. Dim fileStream ' TextStream Object from fso Method OpenTextFile
      4. Dim sysInfo ' ADSystemInfo Object
      5. Dim adUser ' Logged in User
      6. ' Constants for the OpenTextFile Method of the FileSystemObject
      7. Const MODE_READ = 1 'Open for reading
      8. Const MODE_WRITE = 2 'Open for writing
      9. Const MODE_APPEND = 8 'Open to write to end of File
      10. Const FORMAT_ASCII = 0 'Opens file as ASCII (default)
      11. Const FORMAT_UNICODE = -1 'Opens file as Unicode
      12. Const FORMAT_SYSTEM_DEFAULT = -2 'Opens file with whatever is the system default
      13. On Error Resume Next
      14. ' Create Textfile to write in
      15. '==============================================================================================
      16. Set fso = CreateObject("Scripting.FileSystemObject")
      17. targetFile = fso.GetParentFolderName(WScript.ScriptFullName)
      18. targetFile = fso.BuildPath(targetFile, "ADUserInformations.txt")
      19. 'CreateTextFile(Filename, [Overwrite], [Unicode])
      20. fso.CreateTextFile targetFile, true
      21. If Err.Number <> 0 Then
      22. WScript.Echo "Could not create file (" & targetFile & ")."
      23. WScript.Quit
      24. End If
      25. ' Get currently Logged in User
      26. '==============================================================================================
      27. Set sysInfo = CreateObject("ADSystemInfo")
      28. Set adUser = GetObject("LDAP://" & sysInfo.UserName)
      29. If Err.Number <> 0 Then
      30. WScript.Echo "Could not get currently Logged in User"
      31. fso.DeleteFile targetFile
      32. WScript.Quit
      33. End if
      34. ' Get TextStream of created file
      35. '==============================================================================================
      36. 'OpenTextFile(Filename, [Mode], [Create], [Format])
      37. Set fileStream = fso.OpenTextFile(targetFile, _
      38. MODE_APPEND, _
      39. True, _
      40. FORMAT_ASCII)
      41. If Err.Number <> 0 Then
      42. WScript.Echo "Could not create TextStream for file: " & targetFile
      43. fso.DeleteFile targetFile
      44. WScript.Quit
      45. End If
      46. ' Write AD User information into file
      47. '==============================================================================================
      48. fileStream.WriteLine("Scroll down to RESULTS to see what the listed commands return")
      49. fileStream.WriteLine("")
      50. fileStream.WriteLine("How to get the adUser:")
      51. fileStream.WriteLine("================================================")
      52. fileStream.WriteLine("Dim sysInfo 'ADSystemInfo Object")
      53. fileStream.WriteLine("Dim adUser 'Currently Logged in User")
      54. fileStream.WriteLine("")
      55. fileStream.WriteLine("Set sysInfo = CreateObject(""ADSystemInfo"")")
      56. fileStream.WriteLine("Set adUser = GetObject(""LDAP://"" & sysInfo.UserName)")
      57. fileStream.WriteLine("")
      58. fileStream.WriteLine("")
      59. fileStream.WriteLine("")
      60. fileStream.WriteLine("================================================")
      61. fileStream.WriteLine("================================================")
      62. fileStream.WriteLine("COMMAND OVERVIEW")
      63. fileStream.WriteLine("================================================")
      64. fileStream.WriteLine("================================================")
      65. fileStream.WriteLine("adUser.distinguishedName")
      66. fileStream.WriteLine("")
      67. fileStream.WriteLine("GENERAL")
      68. fileStream.WriteLine("================================================")
      69. fileStream.WriteLine("adUser.givenName")
      70. fileStream.WriteLine("adUser.FirstName")
      71. fileStream.WriteLine("adUser.initials")
      72. fileStream.WriteLine("adUser.sn")
      73. fileStream.WriteLine("adUser.LastName")
      74. fileStream.WriteLine("adUser.displayName")
      75. fileStream.WriteLine("adUser.FullName")
      76. fileStream.WriteLine("adUser.description")
      77. fileStream.WriteLine("adUser.physicalDeliveryOfficeName")
      78. fileStream.WriteLine("adUser.telephoneNumber")
      79. fileStream.WriteLine("adUser.otherTelephone")
      80. fileStream.WriteLine("adUser.mail")
      81. fileStream.WriteLine("adUser.EmailAddress")
      82. fileStream.WriteLine("adUser.wWWHomePage")
      83. fileStream.WriteLine("adUser.url")
      84. fileStream.WriteLine("")
      85. fileStream.WriteLine("ADDRESS")
      86. fileStream.WriteLine("================================================")
      87. fileStream.WriteLine("adUser.streetAddress")
      88. fileStream.WriteLine("adUser.postOfficeBox")
      89. fileStream.WriteLine("adUser.l")
      90. fileStream.WriteLine("adUser.st")
      91. fileStream.WriteLine("adUser.postalCode")
      92. fileStream.WriteLine("adUser.countryCode")
      93. fileStream.WriteLine("adUser.c") '(ISO 4217)
      94. fileStream.WriteLine("")
      95. fileStream.WriteLine("ACCOUNT")
      96. fileStream.WriteLine("================================================")
      97. fileStream.WriteLine("adUser.userPrincipalName")
      98. fileStream.WriteLine("adUser.sAMAccountName")
      99. fileStream.WriteLine("adUser.AccountDisabled")
      100. fileStream.WriteLine("adUser.userAccountControl")
      101. fileStream.WriteLine("adUser.logonHours")
      102. fileStream.WriteLine("adUser.userWorkstations")
      103. fileStream.WriteLine("adUser.pwdLastSet")
      104. fileStream.WriteLine("adUser.userAccountControl")
      105. fileStream.WriteLine("adUser.userAccountControl")
      106. fileStream.WriteLine("adUser.userAccountControl")
      107. fileStream.WriteLine("adUser.accountExpires")
      108. fileStream.WriteLine("")
      109. fileStream.WriteLine("PROFILE")
      110. fileStream.WriteLine("adUser.profilePath")
      111. fileStream.WriteLine("adUser.Profile")
      112. fileStream.WriteLine("adUser.scriptPath")
      113. fileStream.WriteLine("adUser.homeDirectory")
      114. fileStream.WriteLine("adUser.homeDrive")
      115. fileStream.WriteLine("adUser.homeDirectory")
      116. fileStream.WriteLine("")
      117. fileStream.WriteLine("TELEPHONE")
      118. fileStream.WriteLine("================================================")
      119. fileStream.WriteLine("adUser.homePhone")
      120. fileStream.WriteLine("adUser.otherHomePhone")
      121. fileStream.WriteLine("adUser.pager")
      122. fileStream.WriteLine("adUser.otherPager")
      123. fileStream.WriteLine("adUser.mobile")
      124. fileStream.WriteLine("adUser.otherMobile")
      125. fileStream.WriteLine("adUser.facsimileTelephoneNumber")
      126. fileStream.WriteLine("adUser.otherFacsimileTelephoneNumber")
      127. fileStream.WriteLine("adUser.ipPhone")
      128. fileStream.WriteLine("adUser.otherIpPhone")
      129. fileStream.WriteLine("adUser.info")
      130. fileStream.WriteLine("")
      131. fileStream.WriteLine("ORGANISATION")
      132. fileStream.WriteLine("================================================")
      133. fileStream.WriteLine("adUser.title")
      134. fileStream.WriteLine("adUser.department")
      135. fileStream.WriteLine("adUser.company")
      136. fileStream.WriteLine("adUser.manager")
      137. fileStream.WriteLine("")
      138. fileStream.WriteLine("")
      139. fileStream.WriteLine("")
      140. fileStream.WriteLine("")
      141. fileStream.WriteLine("================================================")
      142. fileStream.WriteLine("================================================")
      143. fileStream.WriteLine("RESULTS")
      144. fileStream.WriteLine("================================================")
      145. fileStream.WriteLine("================================================")
      146. fileStream.WriteLine("")
      147. fileStream.WriteLine("Distinguished Name: " & adUser.distinguishedName)
      148. fileStream.WriteLine("================================================")
      149. fileStream.WriteLine("")
      150. fileStream.WriteLine("GENERAL")
      151. fileStream.WriteLine("================================================")
      152. fileStream.WriteLine("First name: " & adUser.givenName)
      153. fileStream.WriteLine("First name: " & adUser.FirstName)
      154. fileStream.WriteLine("Initials: " & adUser.initials)
      155. fileStream.WriteLine("Last name: " & adUser.sn)
      156. fileStream.WriteLine("Last name: " & adUser.LastName)
      157. fileStream.WriteLine("Display name: " & adUser.displayName)
      158. fileStream.WriteLine("Display name: " & adUser.FullName)
      159. fileStream.WriteLine("Description: " & adUser.description)
      160. fileStream.WriteLine("Office: " & adUser.physicalDeliveryOfficeName)
      161. fileStream.WriteLine("Telephone number: " & adUser.telephoneNumber)
      162. fileStream.WriteLine("Other Telephone numbers: " & adUser.otherTelephone)
      163. fileStream.WriteLine("Email: " & adUser.mail)
      164. fileStream.WriteLine("Email: " & adUser.EmailAddress)
      165. fileStream.WriteLine("Web page: " & adUser.wWWHomePage)
      166. fileStream.WriteLine("Other Web pages: " & adUser.url)
      167. fileStream.WriteLine("")
      168. fileStream.WriteLine("ADDRESS")
      169. fileStream.WriteLine("================================================")
      170. fileStream.WriteLine("Street: " & adUser.streetAddress)
      171. fileStream.WriteLine("P.O. Box: " & adUser.postOfficeBox)
      172. fileStream.WriteLine("City: " & adUser.l)
      173. fileStream.WriteLine("State/province: " & adUser.st)
      174. fileStream.WriteLine("Zip/Postal Code: " & adUser.postalCode)
      175. fileStream.WriteLine("Country/region: " & adUser.countryCode)
      176. fileStream.WriteLine("Country/region: " & adUser.c) '(ISO 4217)
      177. fileStream.WriteLine("")
      178. fileStream.WriteLine("ACCOUNT")
      179. fileStream.WriteLine("================================================")
      180. fileStream.WriteLine("User logon name: " & adUser.userPrincipalName)
      181. fileStream.WriteLine("pre-Windows 2000 logon name: " & adUser.sAMAccountName)
      182. fileStream.WriteLine("AccountDisabled: " & adUser.AccountDisabled)
      183. fileStream.WriteLine("Account Control #: " & adUser.userAccountControl)
      184. fileStream.WriteLine("Logon Hours: " & adUser.logonHours)
      185. fileStream.WriteLine("Logon On To (Logon Workstations): " & adUser.userWorkstations)
      186. fileStream.WriteLine("User must change password at next logon: " & adUser.pwdLastSet)
      187. fileStream.WriteLine("User cannot change password: " & adUser.userAccountControl)
      188. fileStream.WriteLine("Password never expires: " & adUser.userAccountControl)
      189. fileStream.WriteLine("Store password using reversible encryption: " & adUser.userAccountControl)
      190. fileStream.WriteLine("Account expires end of (date): " & adUser.accountExpires)
      191. fileStream.WriteLine("")
      192. fileStream.WriteLine("PROFILE")
      193. fileStream.WriteLine("================================================")
      194. fileStream.WriteLine("Profile path: " & adUser.profilePath)
      195. fileStream.WriteLine("Profile path: " & adUser.Profile)
      196. fileStream.WriteLine("Logon script: " & adUser.scriptPath)
      197. fileStream.WriteLine("Home folder, local path: " & adUser.homeDirectory)
      198. fileStream.WriteLine("Home folder, Connect, Drive: " & adUser.homeDrive)
      199. fileStream.WriteLine("Home folder, Connect, To:: " & adUser.homeDirectory)
      200. fileStream.WriteLine("")
      201. fileStream.WriteLine("TELEPHONE")
      202. fileStream.WriteLine("================================================")
      203. fileStream.WriteLine("Home: " & adUser.homePhone)
      204. fileStream.WriteLine("Other Home phone numbers: " & adUser.otherHomePhone)
      205. fileStream.WriteLine("Pager: " & adUser.pager)
      206. fileStream.WriteLine("Other Pager numbers: " & adUser.otherPager)
      207. fileStream.WriteLine("Mobile: " & adUser.mobile)
      208. fileStream.WriteLine("Other Mobile numbers: " & adUser.otherMobile)
      209. fileStream.WriteLine("Fax: " & adUser.facsimileTelephoneNumber)
      210. fileStream.WriteLine("Other Fax numbers: " & adUser.otherFacsimileTelephoneNumber)
      211. fileStream.WriteLine("IP phone: " & adUser.ipPhone)
      212. fileStream.WriteLine("Other IP phone numbers: " & adUser.otherIpPhone)
      213. fileStream.WriteLine("Notes: " & adUser.info)
      214. fileStream.WriteLine("")
      215. fileStream.WriteLine("ORGANISATION")
      216. fileStream.WriteLine("================================================")
      217. fileStream.WriteLine("Title: " & adUser.title)
      218. fileStream.WriteLine("Department: " & adUser.department)
      219. fileStream.WriteLine("Company: " & adUser.company)
      220. fileStream.WriteLine("Manager: " & adUser.manager)
      221. fileStream.Close
      222. '==============================================================================================
      223. ' END OF CODE
      224. '==============================================================================================


      *Topic verschoben*

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Marcus Gräfe“ ()