Usuário com melhor resposta
Atualização de atributos de usuário no AD

Pergunta
-
Pessoal,
Na empresa onde eu trabalho surgiu a necessidade de atualizarmos todas as informações que o AD nos possibilidade alimentar. Ramal, setor, gestor... enfim...
Existe algum utilitário ou dica para que eu possa fazer isso de forma mais fácil?
Eu consegui do RH relação completa de todos os colaboradores. É possível fazer um merge ou algo neste sentido?
Respostas
-
Segue o script.
Mas seria melhor se você postasse que precisa. As colunas estão assim:
Coluna 1: Usuario
Coluna 2 : Telefone
Coluna 3: Cargo
Coluna 4: Departamento
Coluna 5: Empresa
Dim sUserPath
Set objNetwork = CreateObject("WScript.Network")
sDomain = objNetwork.UserDomainSet objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open ("C:\users.xls")
intRow = 1
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.closeend function
function getNC
set objRoot=getobject("LDAP://RootDSE")
getNC=objRoot.get("defaultNamingContext")
end functionDo Until objExcel.Cells(intRow,1).Value = ""
cn= objExcel.Cells(intRow, 1).Value
sFone= objExcel.Cells(intRow, 2).Value
sCargo= objExcel.Cells(intRow, 3).Value
sdepartamento= objExcel.Cells(intRow, 4).Value
sEmpresa=objExcel.Cells(intRow, 5).ValuesUserPath = getUserPath(cn)
Set objUser = GetObject(sUserPath)
objUser.Put "homePhone", sFone
objUser.SetInfo
objUser.Put "title", sCargo
objUser.SetInfo
objUser.Put "department", sDepartamento
objUser.SetInfo
objUser.Put "company", sEmpresa
objUser.SetInfowscript.echo cn
intRow = intRow + 1
LoopobjExcel.Quit
Wscript.echo "Concluido"Se for útil vote e qualquer dúvida poste.
Abraço
Gabriel Nascimento MCP / MCSA / CCNA http://gabrielnascimentoit.spaces.live.com -- Se for útil vote.- Marcado como Resposta Richard Juhasz quinta-feira, 29 de abril de 2010 13:51
Todas as Respostas
-
Você quer atualizar as informações dos usuarios?
Se sim, você tem nessa relação o login do usuario? Poste os campos que você vai atualizar e utilizar desse excel, exemplo Coluna 2: Ramal, etc.
Isso é possível atraves de script.
Sugiro que vc feche essa thread e abra uma no fórum de scripts.
Ou então se os moderadores puderem mover esse thread.
Aguardo seu retorno para poder te ajudar no script.
Abraço.
Gabriel Nascimento MCP / MCSA / CCNA http://gabrielnascimentoit.spaces.live.com -- Se for útil vote. -
-
Segue o script.
Mas seria melhor se você postasse que precisa. As colunas estão assim:
Coluna 1: Usuario
Coluna 2 : Telefone
Coluna 3: Cargo
Coluna 4: Departamento
Coluna 5: Empresa
Dim sUserPath
Set objNetwork = CreateObject("WScript.Network")
sDomain = objNetwork.UserDomainSet objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open ("C:\users.xls")
intRow = 1
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.closeend function
function getNC
set objRoot=getobject("LDAP://RootDSE")
getNC=objRoot.get("defaultNamingContext")
end functionDo Until objExcel.Cells(intRow,1).Value = ""
cn= objExcel.Cells(intRow, 1).Value
sFone= objExcel.Cells(intRow, 2).Value
sCargo= objExcel.Cells(intRow, 3).Value
sdepartamento= objExcel.Cells(intRow, 4).Value
sEmpresa=objExcel.Cells(intRow, 5).ValuesUserPath = getUserPath(cn)
Set objUser = GetObject(sUserPath)
objUser.Put "homePhone", sFone
objUser.SetInfo
objUser.Put "title", sCargo
objUser.SetInfo
objUser.Put "department", sDepartamento
objUser.SetInfo
objUser.Put "company", sEmpresa
objUser.SetInfowscript.echo cn
intRow = intRow + 1
LoopobjExcel.Quit
Wscript.echo "Concluido"Se for útil vote e qualquer dúvida poste.
Abraço
Gabriel Nascimento MCP / MCSA / CCNA http://gabrielnascimentoit.spaces.live.com -- Se for útil vote.- Marcado como Resposta Richard Juhasz quinta-feira, 29 de abril de 2010 13:51
-
-
Tenta o script abaixo, mas antes crie uma arquivo CSV conforme apresentado abaixo:
===================ARQUIVO CSV=========================================
Login;Nome Completo;Cargo;Area;Email;Telefone;Empresa;Filial
zeforumba;JOSE FORUMBA; CONSULTOR;Sistemas;;99-3519-2789;AUDITORIA MANSUR;MANSUROBS.: O CAMPO AREA CORRESPONDE A OU QUE O USUÁRIO SE ENCONTRA.
=======================================================================
AO EXECUTAR O SCRIPT ABAIXO UTILIZE: cscript nome_do_vbs.vbs em seguida sera solicitado o nome do
arquivo csv criado acima, entao coloque o nome por exemplo arruma.csv
'
' ArrUser(0) => Login
' ArrUser(1) => Nome Completo
' ArrUser(2) => Cargo
' ArrUser(3) => Area
' ArrUser(4) => Email
' ArrUser(5) => Telefone
' ArrUser(6) => Empresa
' ArrUser(7) => Filial
'
wscript.stdout.write "Qual o arquivo a processar: "
strFile = wscript.stdin.readline
Set oRoot = GetObject("LDAP://rootDSE")
Set oFSO = CreateObject("scripting.FileSystemObject")
on error resume next
Set oFile = oFSO.OpenTextfile(strFile)
if err <> 0 then
wscript.echo err.number & " " & err.description
end if
strCabec = oFile.readline
strDominio = "@" & replace(replace(oRoot.Get("defaultNamingContext"), "DC=" ,""), "," , ".")
do while oFile.AtEndOfStream <> true
ArrUser = split(oFile.ReadLine, ";")
set oOU = GetObject("LDAP://OU=usuarios,OU=" & ArrUser(3) & "," & oRoot.Get("defaultNamingContext"))
if Err <> 0 then
wscript.echo arrUser(0) & " " & err.number & " " & err.description
wscript.echo "Nao foi possivel encontrar a " & "OU=usuarios,OU=" & ArrUser(3) & "," & oRoot.Get("defaultNamingContext")
err.clear
else
set oUser = GetObject("LDAP://cn=" & ArrUser(0) & ",OU=usuarios,OU=" & _
ArrUser(3) & "," & oRoot.Get("defaultNamingContext"))
oUser.put "sAMAccountName", ArrUser(0)
oUser.put "userPrincipalName", ArrUser(0) & strDominio
oUser.put "displayname", ArrUser(1)
oUser.put "description", ArrUser(2)
oUser.put "title", ArrUser(2)
oUser.put "company", ArrUser(6)
oUser.put "department", ArrUser(7)
oUser.put "telephonenumber", ArrUser(5)
oUser.put "mail", ArrUser(4)
oUser.put "physicalDeliveryOfficeName", ArrUser(7)
oUser.SetInfo
if err <> 0 then
' wscript.echo err.number & " - " & err.description
err.clear
end if
end if
Loop
oFile.close