Possível é, mas no próprio AD você consegue esta listagem.
Há algum tempo atrás me pediram isso e tenho este esqueminha:
Cole o script abaixo e salve como como usuario_ad.vbs por exemplo e execute-lo pelo prompt (cmd), passando os parametros domíno e caminho do txt onde será salvo, por exemplo: usuario_ad.vbs dominio.local C:\Usuarios.txt
Set objNetwork = CreateObject("WScript.Network") Set objExcel = CreateObject("Excel.Application")
Function getUserPath(byval sUserName) set cmd=createobject("ADODB.Command") set cn=createobject("ADODB.Connection") set rs=createobject("ADODB.Recordset")
cn.open "Provider=ADsDSOObject;"
cmd.commandtext = "SELECT adspath from 'LDAP://" & getnc & _
"' WHERE objectCategory = 'User' and sAMAccountName = '" & sUserName & "'"
cmd.activeconnection = cn
set rs = cmd.execute
if rs.bof <> true and rs.eof<>true then
getUserPath=rs(0)
else
getUserPath = ""
end if
cn.close
end function
function getNC set objRoot=getobject("[url="ldap://RootDSE"]LDAP://RootDSE[/url]") getNC=objRoot.get("defaultNamingContext") end function
Não sei a fonte, se alguém souber pode postar. Isso ajudou a pessoa na época!
Possível é, mas no próprio AD você consegue esta listagem.
Há algum tempo atrás me pediram isso e tenho este esqueminha:
Cole o script abaixo e salve como como usuario_ad.vbs por exemplo e execute-lo pelo prompt (cmd), passando os parametros domíno e caminho do txt onde será salvo, por exemplo: usuario_ad.vbs dominio.local C:\Usuarios.txt
Set objNetwork = CreateObject("WScript.Network")
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
intRow = 2
objExcel.Cells(1, 1).Value = "Usuario de rede"
objExcel.Cells(1, 2).Value = "Nome Completo"
objExcel.Cells(1, 3).Value = "Descrição"
objExcel.Cells(1, 4).Value = "Email"
objExcel.Cells(1, 5).Value = "Conta Desabilitada?"
'strDomain = InputBox ("Digite o dominio, ex.: dominio.com.br")
strDomain = objNetwork.UserDomain
Set DomObj = GetObject("WinNT://" & strDomain )
DomObj.Filter = Array("User")
For Each objUser In DomObj
UserPath = GetUserPath(objUser.Name)
Set objUserLDAP = getobject(UserPath)
objExcel.Cells(intRow, 1).Value = objUserLDAP.sAMAccountName
objExcel.Cells(intRow, 2).Value = objUserLDAP.DisplayName
objExcel.Cells(intRow, 3).Value = objUserLDAP.Description
objExcel.Cells(intRow, 4).Value = objUserLDAP.mail
objExcel.Cells(intRow, 5).Value = objUserLDAP.AccountDisabled
intRow = intRow + 1
Next
objExcel.Range("A1:E1").Select
objExcel.Selection.Interior.ColorIndex = 19
objExcel.Selection.Font.ColorIndex = 11
objExcel.Selection.Font.Bold = True
objExcel.Cells.EntireColumn.AutoFit
MsgBox "Concluído"
Function getUserPath(byval sUserName)
set cmd=createobject("ADODB.Command")
set cn=createobject("ADODB.Connection")
set rs=createobject("ADODB.Recordset")
cn.open "Provider=ADsDSOObject;"
end function
function getNC
set objRoot=getobject("[url="ldap://RootDSE"]LDAP://RootDSE[/url]")
getNC=objRoot.get("defaultNamingContext")
end function
Não sei a fonte, se alguém souber pode postar. Isso ajudou a pessoa na época!
Abçs
Dando uma olhada na web:
http://int.social.msdn.microsoft.com/Forums/pt-BR/520/thread/1900fdfc-2b69-4ad6-930c-367d36d4b4a3
Abçs