bsharath
asked on
Get the X500 details of all users in a txt file. In Colum B & C & D and So on...
hi,
Get the X500 details of all users/Contacts/Groups in a txt file. In Colum B & C & D and So on
I need to check if all have 2 or more X500 addreses.
I will have the users fullnames or if you want email addresses.
Colum A with the Group/User/Contact name
REgards
sharath
Get the X500 details of all users/Contacts/Groups in a txt file. In Colum B & C & D and So on
I need to check if all have 2 or more X500 addreses.
I will have the users fullnames or if you want email addresses.
Colum A with the Group/User/Contact name
REgards
sharath
So you want to export from Active Directory all users\contacts\groups that have 2 or more X500 addresses? What columns did you want exactly?
ASKER
Colum A the names and there after the X500 addresses
Give this a try. It works like the other script I did for you.
'Define Constants
Const ADS_SCOPE_BASE = 0 'Search base object only
Const ADS_SCOPE_ONELEVEL = 1 'Search one level of immediate children
Const ADS_SCOPE_SUBTREE = 2 ' Search target object and all sub levels
'Create Objects
Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.CreateTextFile("C:\Scripts\Output.csv", True)
'Construct an ADsPath to the Current Domain with rootDSE
Set objRootDSE = GetObject("LDAP://rootDSE")
strADsPath = "LDAP://" & objRootDSE.Get("defaultNamingContext")
'Connect to Active Directory
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_ONELEVEL
'Prompt for path to starting OU
Do
strOUPath = InputBox("Please enter the OU Path to search " & _
" - Seperate OUs with a \", "OU Path Input", "TopOU\SubOU")
If strOUPath = False Then
WScript.Quit
End If
Loop Until strOUPath <> ""
'Split OU path by OU
strOUPath = UCase(strOUPath)
strOUPath = Split(strOUPath, "\")
'Prepare variables for search
intOULevel = 0
strSearchADsPath = strADsPath
'Search through each OU level in path provided
For intOULevel = 0 To UBound(strOUPath)
objCommand.CommandText = "SELECT ADsPath FROM '" & strSearchADsPath & _
"'" & " WHERE objectCategory='organizationalUnit' AND Name = '" & _
strOUPath(intOULevel) & "'"
Set objRecordSet = objCommand.Execute
'Verify OU was found
If objRecordSet.EOF Then
WScript.echo "OU named " & strOUPath(intOULevel) & _
" not found, Exiting script."
WScript.quit
Else
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strSearchADsPath = objRecordSet.Fields("ADsPath").Value
objRecordSet.MoveNext
Loop
End If
Next
'Search AD
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Do
strSearchType = InputBox("Please enter the search type " & _
" - Users or Groups or Contacts", "Input", "")
If strSearchType = False Then
WScript.Quit
End If
Loop Until strSearchType <> ""
strSearchType = UCase(Trim(strSearchType))
Select Case strSearchType
Case "USERS"
UserSub
Case "GROUPS"
GroupSub
Case "CONTACTS"
ContactSub
End Select
objOutputFile.Close
Sub UserSub
WScript.Echo "Users"
objCommand.CommandText = "SELECT samaccountname,proxyAddresses FROM '" & strSearchADsPath & _
"'" & " WHERE objectCategory='person' AND objectClass='user'"
Set objRecordSet = objCommand.Execute
If objRecordSet.EOF Then
WScript.echo "No users found, Exiting script."
WScript.quit
Else
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strName = objRecordSet.Fields("samaccountname").Value
strproxyAddresses = objRecordSet.Fields("proxyAddresses").Value
WScript.Echo strName
If IsArray(strproxyAddresses) Then
strOutput = strName
For Each strproxyaddress In strproxyAddresses
If Left(strproxyaddress, 4) = "X500" Then
strOutput = strOutput & "," & strproxyaddress
End If
Next
objOutputFile.WriteLine strOutput
End If
strOutput = ""
objRecordSet.MoveNext
Loop
End If
End Sub
Sub GroupSub
WScript.Echo "Groups"
objCommand.CommandText = "SELECT cn,proxyAddresses FROM '" & strSearchADsPath & _
"'" & " WHERE objectCategory='group'"
Set objRecordSet = objCommand.Execute
If objRecordSet.EOF Then
WScript.echo "No users found, Exiting script."
WScript.quit
Else
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strName = objRecordSet.Fields("cn").Value
strproxyAddresses = objRecordSet.Fields("proxyAddresses").Value
WScript.Echo strName
If IsArray(strproxyAddresses) Then
strOutput = strName
For Each strproxyaddress In strproxyAddresses
If Left(strproxyaddress, 4) = "X500" Then
strOutput = strOutput & "," & strproxyaddress
End If
Next
objOutputFile.WriteLine strOutput
End If
strOutput = ""
objRecordSet.MoveNext
Loop
End If
End Sub
Sub ContactSub
WScript.Echo "Contacts"
objCommand.CommandText = "SELECT name,proxyAddresses FROM '" & strSearchADsPath & _
"'" & " WHERE objectCategory='person' AND objectClass='contact'"
Set objRecordSet = objCommand.Execute
If objRecordSet.EOF Then
WScript.echo "No users found, Exiting script."
WScript.quit
Else
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strName = objRecordSet.Fields("name").Value
strproxyAddresses = objRecordSet.Fields("proxyAddresses").Value
WScript.Echo strName
If IsArray(strproxyAddresses) Then
strOutput = strName
For Each strproxyaddress In strproxyAddresses
If Left(strproxyaddress, 4) = "X500" Then
strOutput = strOutput & "," & strproxyaddress
End If
Next
objOutputFile.WriteLine strOutput
End If
strOutput = ""
objRecordSet.MoveNext
Loop
End If
End Sub
ASKER
Thanks Nice one
But i get 1 X500 retrieved and not all.
I will have more than 1 X500 address and want all
But i get 1 X500 retrieved and not all.
I will have more than 1 X500 address and want all
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks its perfect .
Is very Useful :-)
Any help on this.. Many have to be related to what you helped
https://www.experts-exchange.com/questions/25692243/Batch-script-or-vbs-to-use-to-replicate-Dc's-2-of-them.html
https://www.experts-exchange.com/questions/25625020/Get-the-X500-details-of-all-users-in-a-txt-file-In-Colum-B-C-D-and-So-on.html
https://www.experts-exchange.com/questions/25555895/Powershell-script-that-checks-if-X500-and-the-user-is-mail-enabled-need-a-way-to-check-in-for-contacts.html
https://www.experts-exchange.com/questions/25631574/Add-X500-for-a-user.html
Is very Useful :-)
Any help on this.. Many have to be related to what you helped
https://www.experts-exchange.com/questions/25692243/Batch-script-or-vbs-to-use-to-replicate-Dc's-2-of-them.html
https://www.experts-exchange.com/questions/25625020/Get-the-X500-details-of-all-users-in-a-txt-file-In-Colum-B-C-D-and-So-on.html
https://www.experts-exchange.com/questions/25555895/Powershell-script-that-checks-if-X500-and-the-user-is-mail-enabled-need-a-way-to-check-in-for-contacts.html
https://www.experts-exchange.com/questions/25631574/Add-X500-for-a-user.html