Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Find AD schema information

Reply
 
Old 07-02-2007   #1 (permalink)
Andy Webster


 
 

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 SpecsSystem Spec
Old 07-03-2007   #2 (permalink)
RichS


 
 

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 SpecsSystem Spec
Old 07-04-2007   #3 (permalink)
Chris Warwick


 
 

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 SpecsSystem Spec
Old 07-04-2007   #4 (permalink)
RichS


 
 

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 SpecsSystem Spec
Old 07-04-2007   #5 (permalink)
/\\/\\o\\/\\/ [MVP]


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46