Hej Script för att hämta ut användare ur AD
    
    
Jag har ett script som jag använder för att hämta ut information om användare ur AD:t. Dom källor jag har använt och på det viset som det har blivit uppbyggt medför att jag bara kan få ut information ur 1 OU åt gången. Finns det något sätt att göa så att detta scriptet känner av om det finns en OU under den nivå den är på och automatiskt går in även i nästa nivå och tar fram info ur det eller måste jag byta ut vilket OU det är som gäller varje gång. 
Kanske det är så att jag kan specificera flera OU åt gången, det är också acceptabelt, men inte heller detta har jag fått att fungera.
Tacksam för all hjälp med detta.
/T
<code>
' 
' This script extracts user data from the AD-OU Specified below, you need to change it
' Data is saved in Excel format in the file c:\test.xls
' The excel file can then be edited, but not the RED marked colums and imported with the
' import script.
' 
'On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
objexcel.Visible = False
objexcel.Workbooks.add
inti = 0
intRow = 2
Set objOU = GetObject("LDAP://OU=CU 1,OU=BU 10,OU=BA 100,OU=mitt bolag,DC=ad,DC=com")
objOU.Filter = Array("user")
For Each objUser in objOU
'	Destinguished Name - Column A
	objExcel.Cells(intRow, 1).Value = objUser.distinguishedName
	ObjExcel.Cells(intRow, 1).Interior.ColorIndex = 3
'	Sign - Column B
	IF objuser.sAMAccountName = "" Then
	ELSE
	objExcel.Cells(intRow, 2).Value = objUser.sAMAccountName
	ObjExcel.Cells(intRow, 2).Interior.ColorIndex = 3 
	END IF
'	Given_Name - Column C
	IF objuser.givenName = "" Then
	ELSE
	objExcel.Cells(intRow, 3).Value = objUser.givenName 
	END IF
'	Surname - Column D
	IF objuser.sn = "" Then
	ELSE
	objExcel.Cells(intRow, 4).Value = objUser.sn 
	END IF
'	Common-Name - Column E
	IF objuser.cn = "" Then
	ELSE
	objExcel.Cells(intRow, 5).Value = objUser.cn
	ObjExcel.Cells(intRow, 5).Interior.ColorIndex = 3
	END IF
'	Employee-Number - Column F
	IF objuser.employeeNumber = "" Then
	ELSE
	objExcel.Cells(intRow, 6).Value = objUser.employeeNumber
	END IF
'	Physical-Delivery-Office-Name - Column G	
	IF objuser.physicalDeliveryOfficeName = "" Then
	ELSE
	objExcel.Cells(intRow, 7).Value = objUser.physicalDeliveryOfficeName
	END IF
'	Address - Column H
	IF objuser.streetAddress = "" Then
	ELSE
	objExcel.Cells(intRow, 8).Value = objUser.streetAddress
	END IF
'	Postal-Code - Column I
	IF objuser.postalCode = "" Then
	ELSE
	objExcel.Cells(intRow, 9).Value = objUser.postalCode
	END IF
'	Locality-Name - Column J
	IF objuser.l = "" Then
	ELSE
	objExcel.Cells(intRow, 10).Value = objUser.l
	END IF
'	Facsimile-Telephone-Number - Column K
	IF objuser.facsimileTelephoneNumber = "" Then
	ELSE
	objExcel.Cells(intRow, 11).Value = ("'" & objUser.facsimileTelephoneNumber & "")
	END IF
'	Telephone-Number - Column L
	IF objuser.telephoneNumber = "" Then
	ELSE
	objExcel.Cells(intRow, 12).Value = ("'" & objUser.telephoneNumber & "")
	END IF
'	Phone-Mobile-Primary - Column M
	IF objuser.mobile = "" Then
	ELSE
	objExcel.Cells(intRow, 13).Value = ("'" & objUser.mobile & "")
	END IF
'	room-Number - Column N
	IF objuser.roomNumber = "" Then
	ELSE
	objExcel.Cells(intRow, 14).Value = objUser.roomNumber
	END IF
'	Address-Home - Column O
	IF objuser.homePostalAddress = "" Then
	ELSE
	objExcel.Cells(intRow, 15).Value = objUser.homePostalAddress
	END IF
'	Phone-Home-Primary - Column P
	IF objuser.homePhone = "" Then
	ELSE
	objExcel.Cells(intRow, 16).Value = ("'" & objUser.homePhone & "")
	END IF
'	Company - Column Q
	IF objuser.company = "" Then
	ELSE
	objExcel.Cells(intRow, 17).Value = objUser.company
	END IF
'	Division - Column R
	IF objuser.division = "" Then
	ELSE
	objExcel.Cells(intRow, 18).Value = objUser.division
	END IF
'	Department - Column S
	IF objuser.department = "" Then
	ELSE
	objExcel.Cells(intRow, 19).Value = objUser.department
	END IF
'	ms-Exch-Extension-Attribute-10 - Column T
	IF objuser.extensionAttribute10 = "" Then
	ELSE
	objExcel.Cells(intRow, 20).Value = objUser.extensionAttribute10
	END IF
	
	intRow = intRow + 1
	inti = inti + 1 
Next
'	Write the Header row to the Excel file
objExcel.Cells(1, 1).Value = "distinguishedName"
objExcel.Cells(1, 1).Font.Bold = TRUE
ObjExcel.Cells(1, 1).Interior.ColorIndex = 36
objExcel.Cells(1, 2).Value = "Sign"
objExcel.Cells(1, 2).Font.Bold = TRUE
ObjExcel.Cells(1, 2).Interior.ColorIndex = 36
objExcel.Cells(1, 3).Value = "Given_Name"
objExcel.Cells(1, 3).Font.Bold = TRUE
ObjExcel.Cells(1, 3).Interior.ColorIndex = 36
objExcel.Cells(1, 4).Value = "Surename"
objExcel.Cells(1, 4).Font.Bold = TRUE
ObjExcel.Cells(1, 4).Interior.ColorIndex = 36
objExcel.Cells(1, 5).Value = "Common-Name"
objExcel.Cells(1, 5).Font.Bold = TRUE
ObjExcel.Cells(1, 5).Interior.ColorIndex = 36
objExcel.Cells(1, 6).Value = "Employee-Number"
objExcel.Cells(1, 6).Font.Bold = TRUE
ObjExcel.Cells(1, 6).Interior.ColorIndex = 36
objExcel.Cells(1, 7).Value = "Physical-Delivery-Office-Name"
objExcel.Cells(1, 7).Font.Bold = TRUE
ObjExcel.Cells(1, 7).Interior.ColorIndex = 36
objExcel.Cells(1, 8).Value = "Address"
objExcel.Cells(1, 8).Font.Bold = TRUE
ObjExcel.Cells(1, 8).Interior.ColorIndex = 36
objExcel.Cells(1, 9).Value = "Postal-Code"
objExcel.Cells(1, 9).Font.Bold = TRUE
ObjExcel.Cells(1, 9).Interior.ColorIndex = 36
objExcel.Cells(1, 10).Value = "Locality-Name"
objExcel.Cells(1, 10).Font.Bold = TRUE
ObjExcel.Cells(1, 10).Interior.ColorIndex = 36
objExcel.Cells(1, 11).Value = "Facsimile-Telephone-Number"
objExcel.Cells(1, 11).Font.Bold = TRUE
ObjExcel.Cells(1, 11).Interior.ColorIndex = 36
objExcel.Cells(1, 12).Value = "Telephone-Number"
objExcel.Cells(1, 12).Font.Bold = TRUE
ObjExcel.Cells(1, 12).Interior.ColorIndex = 36
objExcel.Cells(1, 13).Value = "Phone-Mobile-Primary"
objExcel.Cells(1, 13).Font.Bold = TRUE
ObjExcel.Cells(1, 13).Interior.ColorIndex = 36
objExcel.Cells(1, 14).Value = "roomNumber"
objExcel.Cells(1, 14).Font.Bold = TRUE
ObjExcel.Cells(1, 14).Interior.ColorIndex = 36
objExcel.Cells(1, 15).Value = "Address-Home"
objExcel.Cells(1, 15).Font.Bold = TRUE
ObjExcel.Cells(1, 15).Interior.ColorIndex = 36
objExcel.Cells(1, 16).Value = "Phone-Home-Primary"
objExcel.Cells(1, 16).Font.Bold = TRUE
ObjExcel.Cells(1, 16).Interior.ColorIndex = 36
objExcel.Cells(1, 17).Value = "Company"
objExcel.Cells(1, 17).Font.Bold = TRUE
ObjExcel.Cells(1, 17).Interior.ColorIndex = 36
objExcel.Cells(1, 18).Value = "division"
objExcel.Cells(1, 18).Font.Bold = TRUE
ObjExcel.Cells(1, 18).Interior.ColorIndex = 36
objExcel.Cells(1, 19).Value = "department"
objExcel.Cells(1, 19).Font.Bold = TRUE
ObjExcel.Cells(1, 19).Interior.ColorIndex = 36
objExcel.Cells(1, 20).Value = "extensionAttribute10"
objExcel.Cells(1, 20).Font.Bold = TRUE
objExcel.Cells(1, 20).Interior.ColorIndex = 36
'	Close and Save File
objexcel.ActiveWorkbook.SaveAs("c:\test.xls")
objExcel.Application.Quit
Wscript.Echo ("All Done, Processed " & inti & " entries")
If IsNull(curBonus) Then
    CurBonus = 0
End If
</code>