Тема: VBS:Получение списка учетных записей AD с расширенными свойствами УЗ??
Добрый день, коллеги!
Понадобилось написать скрипт, который будет выгружать БД данные по всем учетным записям в AD. Путем копипаста, получился такой вот скрипт.
'*****************************************************************
'ListAllUsers_GAL_Export1.vbs
' by Paul DiGiorgio
' < pdsd@yahoo.com >
' 30 Aug 2005
'
' This script polls the current domain and looks for
' user objects. If the user object contains data for the
' mail attribute, it outputs the user display name
' then a comma, then the user's mail data.
'*****************************************************************
'1.00 - Created 30 August 2005 by Paul DiGiorgio
'*****************************************************************
'1.01 - Modified 1 September 2005 by Paul DiGiorgio
' - Removed the inputbox, so the file is always called GAL_Export.csv
' If the file already exists, it will be overwritten.
'*****************************************************************
Option Explicit
Dim StartTime,EndTime: StartTime = Now ' For seeing how long the script takes to run
Dim objShell
Dim objFSO
Const ScriptVersion = "1.01"
Set objShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Wscript.Echo "StartTime = " & StartTime
' ***************************************************************** '
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim objRootDSE
Dim objDomain
Dim objContainer
Dim objOrganizationalUnit
Dim strOutputFileName, objOutputFileName, GarbageRC
Dim intUserObjectCountAll, intUserObjectCountSelected
strOutputFileName = "GAL_Export.csv"
Set objOutputFileName = objFSO.OpenTextFile(strOutputFileName, ForWriting, True)
intUserObjectCountAll = 0
intUserObjectCountSelected = 0
Set objRootDSE = GetObject("LDAP://RootDSE")
Set objDomain = GetObject("LDAP://" & objRootDSE.Get("DefaultNamingContext"))
Call Sub_EnumOUs(objDomain.ADsPath)
Sub Sub_EnumOUs(sADsPath)
Set objContainer = GetObject(sADsPath)
objContainer.Filter = Array("OrganizationalUnit")
For Each objOrganizationalUnit in objContainer
WScript.Echo "Checking OU: " & objOrganizationalUnit.ADsPath
Wscript.Echo " User Object Count: " & intUserObjectCountAll
Sub_EnumUsers(objOrganizationalUnit.ADsPath)
Sub_EnumOUs(objOrganizationalUnit.ADsPath)
Next
End Sub
Sub Sub_EnumUsers(sADsPath)
Dim objADobject
Set objContainer = GetObject(sADsPath)
objContainer.Filter = Array("User")
For Each objADobject in objContainer
If objADobject.Class = "user" Then
intUserObjectCountAll = intUserObjectCountAll + 1
If objADobject.department="" Then
objADobject.department= "NULL"
End If
If objADobject.Title ="" Then
objADobject.Title = "NULL"
End If
If objADobject.TelephoneNumber ="" Then
objADobject.TelephoneNumber = "NULL"
End If
If objADobject.mail ="" Then
objADobject.mail = "NULL"
End if
objOutputFileName.Writeline(objADobject.department & "|" & objADobject.Title & "|" & objADobject.TelephoneNumber & "|" & objADobject.displayname & "|" & objADobject.Mail & "|" & objADobject.lockoutTime)
intUserObjectCountSelected = intUserObjectCountSelected + 1
End If
Next
End Sub
objOutputFileName.Close
' ***************************************************************** '
EndTime = Now
Wscript.Echo vbCrLf & "EndTime = " & EndTime
Wscript.Echo "Seconds Elapsed: " & DateDiff("s", StartTime, EndTime)
Wscript.Echo "Script Complete"
Wscript.Quit(0)
' ***************************************************************** 'Скрипт в принципе уже получает все необходимые данные, но не могу получить последнее поле, а именно статус учетки включена/отключена. Подскажите, как можно добраться до этого свойства учетки??

