Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Windows 7 Forum Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

display active directory attributes - not easy question for experts too :-)

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 11-15-2007   #1 (permalink)
IT Staff
Guest


 

display active directory attributes - not easy question for experts too :-)

In vbscript, i did a wscript.echo objmember.samaccountname,
objmember.<attributes>, etc
In Powershell, i can do similar using directorysearcher properties.

My problem lies each time, my administrators wants to look at particular
attribute, i've to change code to reflect what they need. I would like my
script to display what they need, instead of asking me to change the code
each time.

Assuming the input is a text file that contains nt id, i would like a script
name exportattributes.vbs or exportattributes.ps1 that allows administrators
to display what they like to see.

They shld type in like .\exportattributes.ps1 displayname, samaccountname
<nt id.txt file>, which from reading of text file, it will display only :
ntid <tab> displayname <tab> samaccountname

And if they type in like .\exportattributes.ps1 cn, samaccountname <nt
id.txt file>, it will display the relevant info.

How do i approach the problem of coding ?












My System SpecsSystem Spec
Old 11-15-2007   #2 (permalink)
Brandon Shell [MVP]
Guest


 

Re: display active directory attributes - not easy question for experts too :-)

If you think it safe to assume they will get the attribute names correct.
Try this... I am on the bus and cant test it, but it should do what your
looking for.

Param($Attribute)

if($Attribute){$props = $Attribute}
else{$props = "sAMAccoutName"} # add what ever default props you want here

$filter = "(objectcategory=user)"
$ds = New-Object
System.DirectoryServices.DirectorySearcher([ADSI]"",$filter,$prop)
$ds.PageSize = 1000
$Users = $ds.FindAll()
foreach($user in $users)
{
"+ Listing Properties for $($user.properties.samaccountname)"
foreach($prop in $props)
{
" - $Prop : $($user.properties.$prop)"
}
}

"IT Staff" <jkklim@xxxxxx> wrote in message
news:ezp%23mH1JIHA.4584@xxxxxx
Quote:

> In vbscript, i did a wscript.echo objmember.samaccountname,
> objmember.<attributes>, etc
> In Powershell, i can do similar using directorysearcher properties.
>
> My problem lies each time, my administrators wants to look at particular
> attribute, i've to change code to reflect what they need. I would like my
> script to display what they need, instead of asking me to change the code
> each time.
>
> Assuming the input is a text file that contains nt id, i would like a
> script name exportattributes.vbs or exportattributes.ps1 that allows
> administrators to display what they like to see.
>
> They shld type in like .\exportattributes.ps1 displayname, samaccountname
> <nt id.txt file>, which from reading of text file, it will display only :
> ntid <tab> displayname <tab> samaccountname
>
> And if they type in like .\exportattributes.ps1 cn, samaccountname <nt
> id.txt file>, it will display the relevant info.
>
> How do i approach the problem of coding ?
>
>
>
>
>
>
>
>
>
>
>
My System SpecsSystem Spec
Old 11-15-2007   #3 (permalink)
Brandon Shell [MVP]
Guest


 

Re: display active directory attributes - not easy question for experts too :-)

System.DirectoryServices.DirectorySearcher([ADSI]"",$filter,$prop) #<<<
should be $props

"Brandon Shell [MVP]" <a_bshell@xxxxxx> wrote in message
news:62A9BB12-64B6-4112-BC56-512631109B18@xxxxxx
Quote:

> If you think it safe to assume they will get the attribute names correct.
> Try this... I am on the bus and cant test it, but it should do what your
> looking for.
>
> Param($Attribute)
>
> if($Attribute){$props = $Attribute}
> else{$props = "sAMAccoutName"} # add what ever default props you want here
>
> $filter = "(objectcategory=user)"
> $ds = New-Object
> System.DirectoryServices.DirectorySearcher([ADSI]"",$filter,$prop)
> $ds.PageSize = 1000
> $Users = $ds.FindAll()
> foreach($user in $users)
> {
> "+ Listing Properties for $($user.properties.samaccountname)"
> foreach($prop in $props)
> {
> " - $Prop : $($user.properties.$prop)"
> }
> }
>
> "IT Staff" <jkklim@xxxxxx> wrote in message
> news:ezp%23mH1JIHA.4584@xxxxxx
Quote:

>> In vbscript, i did a wscript.echo objmember.samaccountname,
>> objmember.<attributes>, etc
>> In Powershell, i can do similar using directorysearcher properties.
>>
>> My problem lies each time, my administrators wants to look at particular
>> attribute, i've to change code to reflect what they need. I would like my
>> script to display what they need, instead of asking me to change the code
>> each time.
>>
>> Assuming the input is a text file that contains nt id, i would like a
>> script name exportattributes.vbs or exportattributes.ps1 that allows
>> administrators to display what they like to see.
>>
>> They shld type in like .\exportattributes.ps1 displayname, samaccountname
>> <nt id.txt file>, which from reading of text file, it will display only :
>> ntid <tab> displayname <tab> samaccountname
>>
>> And if they type in like .\exportattributes.ps1 cn, samaccountname <nt
>> id.txt file>, it will display the relevant info.
>>
>> How do i approach the problem of coding ?
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: active directory question Richard Mueller [MVP] VB Script 0 06-07-2008 02:30 PM
Active Directory Computer Attributes Anwar Mahmood VB Script 6 06-02-2008 03:21 PM
Why isn't my question being displayed? - Active Directory Problem momentarylapseofreason Vista networking & sharing 4 05-29-2008 04:10 AM
active directory Walser Mark PowerShell 4 04-22-2008 08:55 AM
Active Directory Lothar PowerShell 7 12-14-2006 09:29 AM


Vistax64.com 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 2005-2008

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 47 48 49 50 51