itipu
06-15-2007, 10:46 AM
Hi All. Once again thanks a lot in advance for your great help.
I attached a sample workbook. I am dumping out of Active Directory (AD) cn - machine name values.
I also have a separate sheet in my workbook where there is a table. Column A - list of machine names.
Column B - list of values corresponding to machine name.
Column C - list of values corresponding to machine name.
I would like to have an If statement like this:
'Below "cn" means machine name, if you need to populate further AD attributes, you put as many as you need using "," note there is no comma after the last attribute:
objCommand.CommandText = "SELECT cn FROM " & "'LDAP://linux.xxx.com/dc=linux,dc=xxx,dc=com' WHERE " & "objectCategory='computer'"
Set objRecordSet = objCommand.Execute
objRecordSet.moveFirst
x = 2
Do Until objRecordSet.EOF
If objRecordSet.Fields("cn").Value = VLookup Then
'Below are attributes that are being populate, remember to add these names to SELECT clause above:
objExcel.Cells(x, 1).Value = objRecordSet.Fields("cn").Value
'objExcel.Cells(x, 2).Value = value corresponding to vlookup 1
'objExcel.Cells(x, 2).Value = value corresponding to vlookup 2
x = x + 1
objRecordSet.MoveNext
Else
objRecordSet.MoveNext
End If
Loop
So that whenever I get a cn (machine name from AD) I check if that name is found in my table (located on a sheet). If not, I skip the record. If found I print cn value in Column A of a new sheet, and corresponding values from my table in Column B and Column C...
Tried playing around with vlookup but did not quite get to work right!
Thanks a lot for your help!
Mike
I attached a sample workbook. I am dumping out of Active Directory (AD) cn - machine name values.
I also have a separate sheet in my workbook where there is a table. Column A - list of machine names.
Column B - list of values corresponding to machine name.
Column C - list of values corresponding to machine name.
I would like to have an If statement like this:
'Below "cn" means machine name, if you need to populate further AD attributes, you put as many as you need using "," note there is no comma after the last attribute:
objCommand.CommandText = "SELECT cn FROM " & "'LDAP://linux.xxx.com/dc=linux,dc=xxx,dc=com' WHERE " & "objectCategory='computer'"
Set objRecordSet = objCommand.Execute
objRecordSet.moveFirst
x = 2
Do Until objRecordSet.EOF
If objRecordSet.Fields("cn").Value = VLookup Then
'Below are attributes that are being populate, remember to add these names to SELECT clause above:
objExcel.Cells(x, 1).Value = objRecordSet.Fields("cn").Value
'objExcel.Cells(x, 2).Value = value corresponding to vlookup 1
'objExcel.Cells(x, 2).Value = value corresponding to vlookup 2
x = x + 1
objRecordSet.MoveNext
Else
objRecordSet.MoveNext
End If
Loop
So that whenever I get a cn (machine name from AD) I check if that name is found in my table (located on a sheet). If not, I skip the record. If found I print cn value in Column A of a new sheet, and corresponding values from my table in Column B and Column C...
Tried playing around with vlookup but did not quite get to work right!
Thanks a lot for your help!
Mike