![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Find AD schema information Hi, hope someone can help I am writing a script that I can use to find one or more properties of computer objects in the active directory. The problem I have is getting a list of available properties from the schema. My script currently uses System.DirectoryServices.DirectorySearcher.FindOne method to return a directory entry object for the first computer entry found, searching from the root. I use this to obtain a list of available properties. The problem I have just noticed is this only gives me properties that have been populated on that first object, not all available properties. How can I get a list of all available properties ? Any help would be appreciated. Here is some code which demonstrates the problem: $objDomain = New-Object System.DirectoryServices.DirectoryEntry $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = $objDomain $objSearcher.Filter = ("(objectCategory="computer")") $colResults = $objSearcher.FindAll() $minCount = 1000 $maxCount = 0 foreach ($objResult in $colResults) { $objComputer = $objResult.Properties $objComputer.name + " " + $objComputer.count if($objComputer.Count -lt $minCount){$minCount = $objComputer.Count} if($objComputer.Count -gt $maxCount){$maxCount = $objComputer.Count} } "Min Count:" $minCount "Max Count:" $maxCount |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Find AD schema information You will have to return multiple computer objects and iterate through them testing for the particular properties -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "Andy Webster" wrote: > Hi, hope someone can help > > I am writing a script that I can use to find one or more properties of > computer objects in the active directory. > > The problem I have is getting a list of available properties from the > schema. My script currently uses > System.DirectoryServices.DirectorySearcher.FindOne method to return a > directory entry object for the first computer entry found, searching from the > root. I use this to obtain a list of available properties. > > The problem I have just noticed is this only gives me properties that have > been populated on that first object, not all available properties. > > How can I get a list of all available properties ? > > Any help would be appreciated. > > Here is some code which demonstrates the problem: > > $objDomain = New-Object System.DirectoryServices.DirectoryEntry > $objSearcher = New-Object System.DirectoryServices.DirectorySearcher > $objSearcher.SearchRoot = $objDomain > $objSearcher.Filter = ("(objectCategory="computer")") > $colResults = $objSearcher.FindAll() > $minCount = 1000 > $maxCount = 0 > foreach ($objResult in $colResults) > { > $objComputer = $objResult.Properties > $objComputer.name + " " + $objComputer.count > if($objComputer.Count -lt $minCount){$minCount = $objComputer.Count} > if($objComputer.Count -gt $maxCount){$maxCount = $objComputer.Count} > } > "Min Count:" > $minCount > "Max Count:" > $maxCount > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Find AD schema information On Mon, 2 Jul 2007 05:26:00 -0700, Andy Webster <AndyWebster@discussions.microsoft.com> wrote: > >The problem I have just noticed is this only gives me properties that have >been populated on that first object, not all available properties. > >How can I get a list of all available properties ? > Rather than grabbing random entries and seeing what's available on them the best way to do this is to use S.DS.AD.ActiveDirectorySchemaClass. This has properties such as PossibleInferiors, MandatoryProperties and OptionalProperties which are the values you want. There's an example (in C#, but easily translated) in Kaplan and Dunn's book "The .NET Developer's Guide to Directory Services Programming" - suggest you get hold of a copy - highly recommended! There are some chapters available online - this is detailed in Chapter 7, but I'm not sure if that's one of the free ones... Otherwise, try posting the question on the Microsoft.public.adsi.general group - you're almost guaranteed an instant reply by Joe Kaplan who seems to be one of the world's most prolific posters! HTH Chris |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Find AD schema information Thinking about your original post - the issue is that only populated attributes are returned effectively -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "Chris Warwick" wrote: > On Mon, 2 Jul 2007 05:26:00 -0700, Andy Webster > <AndyWebster@discussions.microsoft.com> wrote: > > > > > >The problem I have just noticed is this only gives me properties that have > >been populated on that first object, not all available properties. > > > >How can I get a list of all available properties ? > > > > Rather than grabbing random entries and seeing what's available on > them the best way to do this is to use > S.DS.AD.ActiveDirectorySchemaClass. This has properties such as > PossibleInferiors, MandatoryProperties and OptionalProperties which > are the values you want. > > There's an example (in C#, but easily translated) in Kaplan and Dunn's > book "The .NET Developer's Guide to Directory Services Programming" - > suggest you get hold of a copy - highly recommended! There are some > chapters available online - this is detailed in Chapter 7, but I'm not > sure if that's one of the free ones... > > Otherwise, try posting the question on the > Microsoft.public.adsi.general group - you're almost guaranteed an > instant reply by Joe Kaplan who seems to be one of the world's most > prolific posters! > > HTH > Chris > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Find AD schema information You can e.g. for a user function get-Schema [System.DirectoryServices.ActiveDirectory.ActiveDirectorySchema]::GetCurrentSchema()} $schema = get-Schema PoSH>$SchemaUser = $schema.FindClass('user') PoSH>$SchemaUser.get_MandatoryProperties() | fl name this examples come from and you can find more information and examples about this on my old blog here : http://mow001.blogspot.com/2006/07/p...ry-part-3.html This code will work the same (not using new ADSI wrapper ) but take care that this is pre RC2 material so on the Directoryentry object you might need to add Psbase in some places Greetings /\/\o\/\/ http://thePowerShellGuy.com "RichS" <RichS@discussions.microsoft.com> wrote in message news:37E59871-8315-4FE1-92D8-C0A791548885@microsoft.com... > Thinking about your original post - the issue is that only populated > attributes are returned effectively > -- > Richard Siddaway > Please note that all scripts are supplied "as is" and with no warranty > Blog: http://richardsiddaway.spaces.live.com/ > PowerShell User Group: http://www.get-psuguk.org.uk > > > "Chris Warwick" wrote: > >> On Mon, 2 Jul 2007 05:26:00 -0700, Andy Webster >> <AndyWebster@discussions.microsoft.com> wrote: >> >> >> > >> >The problem I have just noticed is this only gives me properties that >> >have >> >been populated on that first object, not all available properties. >> > >> >How can I get a list of all available properties ? >> > >> >> Rather than grabbing random entries and seeing what's available on >> them the best way to do this is to use >> S.DS.AD.ActiveDirectorySchemaClass. This has properties such as >> PossibleInferiors, MandatoryProperties and OptionalProperties which >> are the values you want. >> >> There's an example (in C#, but easily translated) in Kaplan and Dunn's >> book "The .NET Developer's Guide to Directory Services Programming" - >> suggest you get hold of a copy - highly recommended! There are some >> chapters available online - this is detailed in Chapter 7, but I'm not >> sure if that's one of the free ones... >> >> Otherwise, try posting the question on the >> Microsoft.public.adsi.general group - you're almost guaranteed an >> instant reply by Joe Kaplan who seems to be one of the world's most >> prolific posters! >> >> HTH >> Chris >> |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| WHERE DO I FIND THE POP3 INFORMATION? | Vista file management | |||
| Where do I find information on this error? | General Discussion | |||
| Extending Active Directory Schema for Bitlocker recovery information | Vista General | |||
| Extending Active Directory Schema for Bitlocker recovery information | Vista security | |||