Monday, March 26, 2012

Loop through all AD properties

Hi,
Can anybody please tell me (or point me to documentation on) how to loop
through all AD properties of a user.
The code I have so far is below.
Now if I know the property name I can retrieve it, for eample to retrieve
"DisplayName"
I would just say.
de.Properties["DisplayName"].Value
so what I would like is just a display of all properties for a user,
something like this
DisplayName
Mail
Title
sAMAccountName
GivenName
it would also be nice to know what type a particular object is, for example
most properties are strings however I believe some properties are "C stucts"
cause they contain more than a single string although just to start I'd be
happy just to get the property names.
any help is appreciated
cheers
martin.
using System;
using System.DirectoryServices;
namespace TestConsole
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
string query;
//query =
ConfigurationSettings.AppSettings.Get("ActiveDirectoryQueryString");
query = "LDAP://mydomain";
System.DirectoryServices.DirectoryEntry entry = new
System.DirectoryServices.DirectoryEntry(query);
System.DirectoryServices.DirectorySearcher mySearcher = new
System.DirectoryServices.DirectorySearcher(entry);
try
{
foreach(System.DirectoryServices.SearchResult resEnt in
mySearcher.FindAll())
{
System.DirectoryServices.DirectoryEntry de=resEnt.GetDirectoryEntry();
//would like to get all properties (property name) here perhaps in a
foreach loop
foreach (DirectoryEntry child in de.Children)
{
Console.WriteLine(child.Name);
}
}
}
catch (Exception ex)
{
Console.WriteLine("ERROR ERROR ERROR " + ex.Message);
}
}
}
}'=======================================
====================================
===============
'
' NAME: GetScriptableProperties.vbs
'
' AUTHOR: Luke Edson, Edsontech
' DATE : 12/09/2004
'
' COMMENT: A sample script that displays the Properties available on an obje
ct, (in this
' case, a User object) & dumps them all to the "UserProperties.log"
log
'
' IMPORTANT:
'
' Copyright (c) 2004 Luke P. Edson -
' Latest Version 1.0 - December 9, 2004
' Original Version 1.0 - December 9, 2004
'
' You have a royalty-free right to use, modify, reproduce, and
' distribute this script file in any way you find useful, provided
' that you agree that the copyright owner above has no warranty,
' obligations, or liability for such use.
'
'=======================================
====================================
===============
On Error Resume Next
Const sOutputFile = "c:\UserProperties.log" 'output log file
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set objFS = CreateObject("Scripting.FileSystemObject")
If objFS.FileExists(sOutputFile) Then
Set OutFile = objFS.OpenTextFile(sOutputFile, ForAppending, True)
Else
Set OutFile = objFS.OpenTextFile(SOutputFile, ForWriting, True)
End If
Set objSysInfo = CreateObject("ADSystemInfo")
OutFile.WriteLine "Getting User" & objSysInfo.UserName
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
Set objClass = GetObject(objUser.Schema)
' Enumerate mandatory properties of the object.
For Each strProperty In objClass.MandatoryProperties
OutFile.WriteLine "(M) " & strProperty
Next
' Enumerate optional properties of the object.
For Each strProperty In objClass.OptionalProperties
OutFile.WriteLine "(O) " & strProperty
Next
I know this is an old post, but i was looking for all properties for a AD us
er too.
I used the VB script below, in Visual Studio 2005. Only Added declarations f
or some stuff. (Dim WSHShell) ect...
But if you just need a simpel list, i have postet the list, as it is in my A
ctive Directory.
Please bear in mind that this list can be different in your AD, do to Exchan
ge features ect.
Getting UserCN=Testuser1,OU=myou,OU=User Accounts,DC=test,DC=com
(M) cn
(M) instanceType
(M) nTSecurityDescriptor
(M) objectCategory
(M) objectClass
(M) objectSid
(M) sAMAccountName
(O) accountExpires
(O) accountNameHistory
(O) aCSPolicyName
(O) adminCount
(O) adminDescription
(O) adminDisplayName
(O) allowedAttributes
(O) allowedAttributesEffective
(O) allowedChildClasses
(O) allowedChildClassesEffective
(O) altRecipient
(O) altRecipientBL
(O) altSecurityIdentities
(O) assistant
(O) attributeCertificate
(O) attributeCertificateAttribute
(O) audio
(O) authOrig
(O) authOrigBL
(O) autoReply
(O) autoReplyMessage
(O) badPasswordTime
(O) badPwdCount
(O) bridgeheadServerListBL
(O) businessCategory
(O) businessRoles
(O) c
(O) canonicalName
(O) carLicense
(O) co
(O) codePage
(O) comment
(O) company
(O) controlAccessRights
(O) countryCode
(O) createTimeStamp
(O) dBCSPwd
(O) defaultClassStore
(O) deletedItemFlags
(O) delivContLength
(O) deliverAndRedirect
(O) deliveryMechanism
(O) delivExtContTypes
(O) department
(O) departmentNumber
(O) description
(O) desktopProfile
(O) destinationIndicator
(O) directReports
(O) displayName
(O) displayNamePrintable
(O) distinguishedName
(O) division
(O) dLMemDefault
(O) dLMemRejectPerms
(O) dLMemRejectPermsBL
(O) dLMemSubmitPerms
(O) dLMemSubmitPermsBL
(O) dnQualifier
(O) dSASignature
(O) dSCorePropagationData
(O) DUP-labeledURI-d03c92a6-86ba-47a4-9821-025e05c06616
(O) DUP-secretary-84b249b9-21bb-4e0b-bfc1-77ae242b5d0c
(O) dynamicLDAPServer
(O) employeeID
(O) employeeNumber
(O) employeeType
(O) enabledProtocols
(O) expirationTime
(O) extensionAttribute1
(O) extensionAttribute10
(O) extensionAttribute11
(O) extensionAttribute12
(O) extensionAttribute13
(O) extensionAttribute14
(O) extensionAttribute15
(O) extensionAttribute2
(O) extensionAttribute3
(O) extensionAttribute4
(O) extensionAttribute5
(O) extensionAttribute6
(O) extensionAttribute7
(O) extensionAttribute8
(O) extensionAttribute9
(O) extensionData
(O) extensionName
(O) facsimileTelephoneNumber
(O) fen-UM-AllowChargecodeOverride
(O) fen-UM-AllowCoversheetOverride
(O) fen-UM-AllowedToSendFax
(O) fen-UM-AllowedToSendFaxInt
(O) fen-UM-AllowedToSendSms
(O) fen-UM-AllowedToSendSmsInt
(O) fen-UM-AllowedToSendStx
(O) fen-UM-AllowedToSendTlx
(O) fen-UM-Chargecode
(O) fen-UM-Coversheet
(O) fen-UM-Fileformat
(O) flags
(O) folderPathname
(O) formData
(O) forwardingAddress
(O) fromEntry
(O) frsComputerReferenceBL
(O) fRSMemberReferenceBL
(O) fSMORoleOwner
(O) garbageCollPeriod
(O) generationQualifier
(O) givenName
(O) groupMembershipSAM
(O) groupPriority
(O) groupsToIgnore
(O) heuristics
(O) homeDirectory
(O) homeDrive
(O) homeMDB
(O) homeMTA
(O) homePhone
(O) homePostalAddress
(O) houseIdentifier
(O) importedFrom
(O) info
(O) initials
(O) internationalISDNNumber
(O) internetEncoding
(O) ipPhone
(O) isCriticalSystemObject
(O) isDeleted
(O) isPrivilegeHolder
(O) jpegPhoto
(O) kMServer
(O) l
(O) language
(O) languageCode
(O) lastKnownParent
(O) lastLogoff
(O) lastLogon
(O) lastLogonTimestamp
(O) legacyExchangeDN
(O) lmPwdHistory
(O) localeID
(O) lockoutTime
(O) logonCount
(O) logonHours
(O) logonWorkstation
(O) mail
(O) mailNickname
(O) managedObjects
(O) manager
(O) mAPIRecipient
(O) masteredBy
(O) maxStorage
(O) mDBOverHardQuotaLimit
(O) mDBOverQuotaLimit
(O) mDBStorageQuota
(O) mDBUseDefaults
(O) memberOf
(O) mhsORAddress
(O) middleName
(O) mobile
(O) modifyTimeStamp
(O) mS-DS-ConsistencyChildCount
(O) mS-DS-ConsistencyGuid
(O) mS-DS-CreatorSID
(O) msCOM-PartitionSetLink
(O) msCOM-UserLink
(O) msCOM-UserPartitionSetLink
(O) msDRM-IdentityCertificate
(O) msDS-AllowedToDelegateTo
(O) msDS-Approx-Immed-Subordinates
(O) msDS-Cached-Membership
(O) msDS-Cached-Membership-Time-Stamp
(O) msDS-KeyVersionNumber
(O) msDs-masteredBy
(O) msDS-MembersForAzRoleBL
(O) msDS-NCReplCursors
(O) msDS-NCReplInboundNeighbors
(O) msDS-NCReplOutboundNeighbors
(O) msDS-NonMembersBL
(O) msDS-ObjectReferenceBL
(O) msDS-OperationsForAzRoleBL
(O) msDS-OperationsForAzTaskBL
(O) msDS-ReplAttributeMetaData
(O) msDS-ReplValueMetaData
(O) msDS-Site-Affinity
(O) msDS-TasksForAzRoleBL
(O) msDS-TasksForAzTaskBL
(O) msDS-User-Account-Control-Computed
(O) msExchADCGlobalNames
(O) msExchALObjectVersion
(O) msExchAssistantName
(O) msExchConferenceMailboxBL
(O) msExchControllingZone
(O) msExchCustomProxyAddresses
(O) msExchExpansionServerName
(O) msExchFBURL
(O) msExchHideFromAddressLists
(O) msExchHomeServerName
(O) msExchHouseIdentifier
(O) msExchIMACL
(O) msExchIMAddress
(O) msExchIMAPOWAURLPrefixOverride
(O) msExchIMMetaPhysicalURL
(O) msExchIMPhysicalURL
(O) msExchIMVirtualServer
(O) msExchInconsistentState
(O) msExchLabeledURI
(O) msExchMailboxFolderSet
(O) msExchMailboxGuid
(O) msExchMailboxSecurityDescriptor
(O) msExchMailboxUrl
(O) msExchMasterAccountSid
(O) msExchOmaAdminExtendedSettings
(O) msExchOmaAdminWirelessEnable
(O) msExchOriginatingForest
(O) msExchPfRootUrl
(O) msExchPoliciesExcluded
(O) msExchPoliciesIncluded
(O) msExchPolicyEnabled
(O) msExchPolicyOptionList
(O) msExchPreviousAccountSid
(O) msExchProxyCustomProxy
(O) msExchQueryBaseDN
(O) msExchRecipLimit
(O) msExchRequireAuthToSendTo
(O) msExchResourceGUID
(O) msExchResourceProperties
(O) msExchTUIPassword
(O) msExchTUISpeed
(O) msExchTUIVolume
(O) msExchUnmergedAttsPt
(O) msExchUseOAB
(O) msExchUserAccountControl
(O) msExchVoiceMailboxID
(O) msIIS-FTPDir
(O) msIIS-FTPRoot
(O) mSMQDigests
(O) mSMQDigestsMig
(O) mSMQSignCertificates
(O) mSMQSignCertificatesMig
(O) msNPAllowDialin
(O) msNPCallingStationID
(O) msNPSavedCallingStationID
(O) msRADIUSCallbackNumber
(O) msRADIUSFramedIPAddress
(O) msRADIUSFramedRoute
(O) msRADIUSServiceType
(O) msRASSavedCallbackNumber
(O) msRASSavedFramedIPAddress
(O) msRASSavedFramedRoute
(O) name
(O) netbootSCPBL
(O) networkAddress
(O) nonSecurityMemberBL
(O) ntPwdHistory
(O) o
(O) objectGUID
(O) objectVersion
(O) operatorCount
(O) otherFacsimileTelephoneNumber
(O) otherHomePhone
(O) otherIpPhone
(O) otherLoginWorkstations
(O) otherMailbox
(O) otherMobile
(O) otherPager
(O) otherTelephone
(O) otherWellKnownObjects
(O) ou
(O) ownerBL
(O) pager
(O) partialAttributeDeletionList
(O) partialAttributeSet
(O) personalPager
(O) personalTitle
(O) photo
(O) physicalDeliveryOfficeName
(O) pOPCharacterSet
(O) pOPContentFormat
(O) possibleInferiors
(O) postalAddress
(O) postalCode
(O) postOfficeBox
(O) preferredDeliveryMethod
(O) preferredLanguage
(O) preferredOU
(O) primaryGroupID
(O) primaryInternationalISDNNumber
(O) primaryTelexNumber
(O) profilePath
(O) protocolSettings
(O) proxiedObjectName
(O) proxyAddresses
(O) publicDelegates
(O) publicDelegatesBL
(O) pwdLastSet
(O) queryPolicyBL
(O) registeredAddress
(O) replicatedObjectVersion
(O) replicationSensitivity
(O) replicationSignature
(O) replPropertyMetaData
(O) replUpToDateVector
(O) repsFrom
(O) repsTo
(O) revision
(O) rid
(O) roomNumber
(O) sAMAccountType
(O) scriptPath
(O) sDRightsEffective
(O) securityIdentifier
(O) securityProtocol
(O) seeAlso
(O) serialNumber
(O) serverReferenceBL
(O) servicePrincipalName
(O) showInAddressBook
(O) showInAdvancedViewOnly
(O) sIDHistory
(O) siteObjectBL
(O) sn
(O) st
(O) street
(O) streetAddress
(O) structuralObjectClass
(O) submissionContLength
(O) subRefs
(O) subSchemaSubEntry
(O) supplementalCredentials
(O) supportedAlgorithms
(O) systemFlags
(O) targetAddress
(O) telephoneAssistant
(O) telephoneNumber
(O) teletexTerminalIdentifier
(O) telexNumber
(O) terminalServer
(O) textEncodedORAddress
(O) thumbnailLogo
(O) thumbnailPhoto
(O) title
(O) tokenGroups
(O) tokenGroupsGlobalAndUniversal
(O) tokenGroupsNoGCAcceptable
(O) uid
(O) unauthOrig
(O) unauthOrigBL
(O) unicodePwd
(O) unmergedAtts
(O) url
(O) userAccountControl
(O) userCert
(O) userCertificate
(O) userParameters
(O) userPassword
(O) userPKCS12
(O) userPrincipalName
(O) userSharedFolder
(O) userSharedFolderOther
(O) userSMIMECertificate
(O) userWorkstations
(O) uSNChanged
(O) uSNCreated
(O) uSNDSALastObjRemoved
(O) USNIntersite
(O) uSNLastObjRem
(O) uSNSource
(O) versionNumber
(O) wbemPath
(O) wellKnownObjects
(O) whenChanged
(O) whenCreated
(O) wWWHomePage
(O) x121Address
(O) x500uniqueIdentifier
quote:
Originally posted by ledson
'====================================
=======================================
===============
'
' NAME: GetScriptableProperties.vbs
'
' AUTHOR: Luke Edson, Edsontech
' DATE : 12/09/2004
'
' COMMENT: A sample script that displays the Properties available on an obje
ct, (in this
' case, a User object) & dumps them all to the "UserProperties.log"
log
'
' IMPORTANT:
'
' Copyright (c) 2004 Luke P. Edson -
' Latest Version 1.0 - December 9, 2004
' Original Version 1.0 - December 9, 2004
'
' You have a royalty-free right to use, modify, reproduce, and
' distribute this script file in any way you find useful, provided
' that you agree that the copyright owner above has no warranty,
' obligations, or liability for such use.
'
'=======================================
====================================
===============
On Error Resume Next
Const sOutputFile = "c:\UserProperties.log" 'output log file
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set objFS = CreateObject("Scripting.FileSystemObject")
If objFS.FileExists(sOutputFile) Then
Set OutFile = objFS.OpenTextFile(sOutputFile, ForAppending, True)
Else
Set OutFile = objFS.OpenTextFile(SOutputFile, ForWriting, True)
End If
Set objSysInfo = CreateObject("ADSystemInfo")
OutFile.WriteLine "Getting User" & objSysInfo.UserName
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
Set objClass = GetObject(objUser.Schema)
' Enumerate mandatory properties of the object.
For Each strProperty In objClass.MandatoryProperties
OutFile.WriteLine "(M) " & strProperty
Next
' Enumerate optional properties of the object.
For Each strProperty In objClass.OptionalProperties
OutFile.WriteLine "(O) " & strProperty
Next

0 comments:

Post a Comment