Below VB script allows you to update the Computer description from CSV file in Active directiory
set Input_Connection = createobject("adodb.connection")
set Input_RecordSet = createobject("adodb.recordset")
Comp_Location ="C:\AD\"
'CONNECT TO CSV file
Input_Connection.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & _
Comp_Location & ";Extended Properties=""text;HDR=YES;FMT=Delimited"""
Input_RecordSet.open "SELECT * FROM Computers.csv",Input_Connection
strDomain= DOMAIN_NAME
Set objRootLDAP = GetObject("LDAP://RootDSE")
strDNSDomain = objRootLDAP.Get("DefaultNamingContext")
strOU = OU PATH
set objRootDSE = GetObject("LDAP://" & strDomain & "/RootDSE")
set objContainer = GetObject("LDAP://cn=Computers," & objRootDSE.Get("defaultNamingContext"))
set oLogObject = CreateObject("Scripting.FileSystemObject")
set oLogOutput = oLogObject.CreateTextFile("C:\UsersComputer.log")
oLogOutput.WriteLine Now & ": Log started"
On Error Resume Next
do until Input_RecordSet.EOF
oLogOutput.WriteLine "A:" & strComputer & strOU & strDNSDomain
strDescr =Input_RecordSet.Fields.Item(1).Value
strComputer = "CN=" & Input_RecordSet.Fields.Item(0).Value & ","
set objComputer = GetObject("LDAP://"& strComputer & strOU & strDNSDomain)
objComputer.Put "description", strDescr
objComputer.SetInfo
Input_RecordSet.movenext
Loop
"Scripting" is basically giving sequential instructions to computer for doing specific things rather than doing manually. Sometimes we need to write a small and quick vbscript (.vbs), javascript(.js), batch file(.bat) or SQL script(.sql) to perform a short task, but we lack information or get confuse on where to start or which scrpit to write. In my BLOG, I will try to cover as many different scripts as possible that will be useful to everyone.
No comments:
Post a Comment