bsharath
asked on
Query a OU and all OU's below it and get the details
Query a OU and all OU's below it and get the Display name,Description,Email id and forwarded user name and email id.
We have a contact set as forward thats in a different OU. So need a combined list from it
We have a contact set as forward thats in a different OU. So need a combined list from it
Use CSVDE:
csvde -f OUTPUT.CSV -d "cn=users,DC=DOMAINNAME,DC =Microsoft ,DC=Com" -r "(objectClass=user)"
You can also add the -l switch and specify specific attributes such as sAMAccountName
csvde -f OUTPUT.CSV -d "cn=users,DC=DOMAINNAME,DC
You can also add the -l switch and specify specific attributes such as sAMAccountName
Hi, try this.
Regards,
Rob.
Regards,
Rob.
strOU = "OU=SecondOU,OU=FirstOU,DC=domain,DC=com"
strOutput = "UserForwards.csv"
' Setup FSO objects.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutput = objFSO.CreateTextFile(strOutput, True)
objOutput.WriteLine """Username"",""DisplayName"",""Description"",""Email"",""Alt Username"",""Alt DisplayName"",""Alt Email"""
' Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
strBase = "<LDAP://" & strOU & ">"
strFilter = "(&(objectCategory=person)(objectClass=user))"
strAttributes = "adsPath"
strScope = "subtree"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";" & strScope
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute
Do Until adoRecordset.EOF
Set objUser = adoRecordset.Fields("adsPath").Value
strUsername = objUser.samAccountName
strDisplayName = objUser.DisplayName
strDescription = objUser.Description
strEmail = objUser.mail
strAltRecipient = objUser.altRecipient
If strAltRecipient <> "" Then
Set objForwardedUser = GetObject("LDAP://" & strAltRecipient)
strForwardedUsername = objForwardedUser.samAccountName
strForwardedDisplayName = objForwardedUser.displayName
strForwardedEmail = objForwardedUser.mail
Else
strForwardedUsername = ""
strForwardedDisplayName = ""
strForwardedEmail = ""
End If
objOutput.WriteLine """" & strUsername & """,""" & strDisplayName & """,""" & strDescription & """,""" & strEmail & """,""" & strForwardedUsername & """,""" & strForwardedDisplayName & """,""" & strForwardedEmail & """"
adoRecordset.MoveNext
Loop
adoRecordset.Close
adoConnection.Close
objOutput.Close
WScript.Echo "Finished"
ASKER
Thanks Rob
I get this
-------------------------- -
Windows Script Host
-------------------------- -
Script: D:\Get details AD with forwards.vbs
Line: 25
Char: 1
Error: Table does not exist.
Code: 80040E37
Source: Provider
-------------------------- -
OK
-------------------------- -
I get this
--------------------------
Windows Script Host
--------------------------
Script: D:\Get details AD with forwards.vbs
Line: 25
Char: 1
Error: Table does not exist.
Code: 80040E37
Source: Provider
--------------------------
OK
--------------------------
You will need to make sure that this line is structured properly:
strOU = "OU=SecondOU,OU=FirstOU,DC =domain,DC =com"
and do not put the LDAP:// at the start.
Rob.
strOU = "OU=SecondOU,OU=FirstOU,DC
and do not put the LDAP:// at the start.
Rob.
ASKER
Now get this
-------------------------- -
Windows Script Host
-------------------------- -
Script: D:\Get details AD with forwards.vbs
Line: 27
Char: 2
Error: Object required: '[string: "LDAP://CN=Uha Si,O"]'
Code: 800A01A8
Source: Microsoft VBScript runtime error
-------------------------- -
OK
-------------------------- -
--------------------------
Windows Script Host
--------------------------
Script: D:\Get details AD with forwards.vbs
Line: 27
Char: 2
Error: Object required: '[string: "LDAP://CN=Uha Si,O"]'
Code: 800A01A8
Source: Microsoft VBScript runtime error
--------------------------
OK
--------------------------
Oops, plase change
Set objUser = adoRecordset.Fields("adsPa th").Value
to
Set objUser = GetObject(adoRecordset.Fie lds("adsPa th").Value )
Regards,
Rob.
Set objUser = adoRecordset.Fields("adsPa
to
Set objUser = GetObject(adoRecordset.Fie
Regards,
Rob.
ASKER
perfect Rob
One change
Can we have 4 OU's excluded within the root we scan
One change
Can we have 4 OU's excluded within the root we scan
Do you want each OU, and then each sub OU excluded?
For example, if you scan
domain.com/FirstOU/SecondO U
and then exclude
domain.com/FirstOU/SecondO U/ThirdOU
do you also want it to exclude
domain.com/FirstOU/SecondO U/ThirdOU/ FourthOU
as well, or ONLY ThirdOU?
Rob.
For example, if you scan
domain.com/FirstOU/SecondO
and then exclude
domain.com/FirstOU/SecondO
do you also want it to exclude
domain.com/FirstOU/SecondO
as well, or ONLY ThirdOU?
Rob.
ASKER
I scan OURoot
Exclude 3 OU's that i mention exactly
Not the Ou;s that are within the excluded OU
Say i have
>OU1
>>OU2
>>OU3
If i exclude OU1 then OU2 and OU3 has to be scanned
If excluded OU3 then OU1 and OU2 should be scanned
Exclude 3 OU's that i mention exactly
Not the Ou;s that are within the excluded OU
Say i have
>OU1
>>OU2
>>OU3
If i exclude OU1 then OU2 and OU3 has to be scanned
If excluded OU3 then OU1 and OU2 should be scanned
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ASKER
Hi Rob..
Any help with this
https://www.experts-exchange.com/questions/27314689/Hosts-file-update-with-2-records-remotely.html
Any help with this
https://www.experts-exchange.com/questions/27314689/Hosts-file-update-with-2-records-remotely.html
You can use this tool :
http://www.manageengine.com/products/free-windows-active-directory-tools/free-windows-active-directory-query-tool.html
is very easy to use and to configure.
If you prefer i can post the correct syntax for you to query from command prompt but i perfer that tool to make that kind of query ;)
NM