Windows Vista Forums
Vista Forums Home Join Vista Forums Donate 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

formatting AD output

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 01-31-2008   #1 (permalink)
Kev T
Guest


 

formatting AD output

I have the standard ad search script...

$objDomain = New-Object System.DirectoryServices.DirectoryEntry

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
#$objSearcher.PageSize = 10000
$objSearcher.Filter = "(&(objectCategory=Computer)
(operatingSystem=*server*))"


$colProplist = "name","operatingsystemservicepack","Created"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}

$colResults = $objSearcher.FindAll()

foreach ($objResult in $colResults)
# {Write $ObjResult.Properties}
{$objItem = $objResult.Properties; $objItem.created; $objItem.name;
$ObjItem.operatingsystemservicepack}# | export-csv "C:\servers.csv"}


the output gives me

%Servername%
Service Pack 1
%Servername%
Service Pack 2

How can I alter the output to %Servername% , Service Pack 1

I have tried adding things along the line of.....

+ "," + but does not seem to work.

Many thanks

Kev

My System SpecsSystem Spec
Old 01-31-2008   #2 (permalink)
alexandair
Guest


 

Re: formatting AD output

On Jan 31, 11:04*am, Kev T <K...@xxxxxx> wrote:
Quote:

> I have the standard ad search script...
>
> $objDomain = New-Object System.DirectoryServices.DirectoryEntry
>
> $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
> $objSearcher.SearchRoot = $objDomain
> #$objSearcher.PageSize = 10000
> $objSearcher.Filter = "(&(objectCategory=Computer)
> (operatingSystem=*server*))"
>
> $colProplist = "name","operatingsystemservicepack","Created"
> foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
>
> $colResults = $objSearcher.FindAll()
>
> foreach ($objResult in $colResults)
> # * * * {Write $ObjResult.Properties}
> * * {$objItem = $objResult.Properties; $objItem.created; $objItem.name;
> $ObjItem.operatingsystemservicepack}# | export-csv "C:\servers.csv"}
>
> the output gives me
>
> %Servername%
> Service Pack 1
> %Servername%
> Service Pack 2
>
> How can I alter the output to %Servername% , Service Pack 1
>
> I have tried adding things along the line of.....
>
> + "," + but does not seem to work.
>
> Many thanks
>
> Kev
write-host $objItem.name "," $ObjItem.operatingsystemservicepack

-aleksandar
http://powershellers.blogspot.com
My System SpecsSystem Spec
Old 01-31-2008   #3 (permalink)
Shay Levi
Guest


 

Re: formatting AD output

Try:


(...)
$colResults | foreach {
$objItem = $_.Properties
$obj = new-object psobject
add-member -inp $obj noteproperty name $($objItem.name)
add-member -inp $obj noteproperty operatingsystemservicepack $($objItem.operatingsystemservicepack)
$obj
} | export-csv C:\servers.csv -noType



-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> I have the standard ad search script...
>
> $objDomain = New-Object System.DirectoryServices.DirectoryEntry
>
> $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
> $objSearcher.SearchRoot = $objDomain
> #$objSearcher.PageSize = 10000
> $objSearcher.Filter = "(&(objectCategory=Computer)
> (operatingSystem=*server*))"
> $colProplist = "name","operatingsystemservicepack","Created" foreach
> ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
>
> $colResults = $objSearcher.FindAll()
>
> foreach ($objResult in $colResults)
> # {Write $ObjResult.Properties}
> {$objItem = $objResult.Properties; $objItem.created;
> $objItem.name;
> $ObjItem.operatingsystemservicepack}# | export-csv "C:\servers.csv"}
> the output gives me
>
> %Servername%
> Service Pack 1
> %Servername%
> Service Pack 2
> How can I alter the output to %Servername% , Service Pack 1
>
> I have tried adding things along the line of.....
>
> + "," + but does not seem to work.
>
> Many thanks
>
> Kev
>

My System SpecsSystem Spec
Old 01-31-2008   #4 (permalink)
Kev T
Guest


 

Re: formatting AD output

Shay,

superb

thank you, just what i was looking for. Just google'ing why it works now...

Alexandiar gives me a undefined error just using ","

thanks again guys

Kev

"Shay Levi" wrote:
Quote:

> Try:
>
>
> (...)
> $colResults | foreach {
> $objItem = $_.Properties
> $obj = new-object psobject
> add-member -inp $obj noteproperty name $($objItem.name)
> add-member -inp $obj noteproperty operatingsystemservicepack $($objItem.operatingsystemservicepack)
> $obj
> } | export-csv C:\servers.csv -noType
>
>
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

> > I have the standard ad search script...
> >
> > $objDomain = New-Object System.DirectoryServices.DirectoryEntry
> >
> > $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
> > $objSearcher.SearchRoot = $objDomain
> > #$objSearcher.PageSize = 10000
> > $objSearcher.Filter = "(&(objectCategory=Computer)
> > (operatingSystem=*server*))"
> > $colProplist = "name","operatingsystemservicepack","Created" foreach
> > ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
> >
> > $colResults = $objSearcher.FindAll()
> >
> > foreach ($objResult in $colResults)
> > # {Write $ObjResult.Properties}
> > {$objItem = $objResult.Properties; $objItem.created;
> > $objItem.name;
> > $ObjItem.operatingsystemservicepack}# | export-csv "C:\servers.csv"}
> > the output gives me
> >
> > %Servername%
> > Service Pack 1
> > %Servername%
> > Service Pack 2
> > How can I alter the output to %Servername% , Service Pack 1
> >
> > I have tried adding things along the line of.....
> >
> > + "," + but does not seem to work.
> >
> > Many thanks
> >
> > Kev
> >
>
>
>
My System SpecsSystem Spec
Old 01-31-2008   #5 (permalink)
Server Bitch
Guest


 

Re: formatting AD output

Hi Shay,

I have a similar problem as Kev howerver I'm passing arguments from the
commandline so I can use the AD search script as a function in my profile. I
have got as far as finding a quick fix that transposes the results to
coloumns but i can only get it to work with two arguments as the hash table
is (2*2). I need it to work with x number of arguments or at least 3*3.
Please could you show me (or point me in the right direction) to modify the
following already plagerised snippet.

CODE TO TRANSPOSE OUTPUT :
$list = 1,one,2,two,3,three
$hash = @{} ; while ($list) { $key, $value, $list = $list;
$hash[$key]=$value }

gives output
1 one
2 two
3 three
4 four

FUNCTION :

Function adsmore
{
$argument0 = $args[0]
$argument1 = $args[1]
$argument2 = $args[2]
$argument3 = $args[3]
$argument4 = $args[4]
$dom =
[System.DirectoryServices.ActiveDirectory.Domain]::getcurrentdomain().name

#Create New object to search AD

$domain = New-Object DirectoryServices.DirectoryEntry

#Set Search

$search = [System.DirectoryServices.DirectorySearcher]$domain

#Choose Search Filter objectClass "(&(objectCategory=Computer)

(operatingSystem=*Server*))" = servers or replace
(objectCategory=User),Object=Group .. Etc #So first is the Object type or
class USER,GROUP,COMPUTER etc, the second is the attribute within that
objectclass.

$search.Filter =
"(&(objectClass=$argument0)($argument1=$argument2)($argument3=$argument4))"

#Go Get it

$user = $search.Findall()

foreach($users in $user){

$Objitem = $users.properties; $objItem.name; $objitem.$argument1;
$objitem.$argument2; $objitem.$argument3; $objitem.$argument4}
}








"Kev T" wrote:
Quote:

> Shay,
>
> superb
>
> thank you, just what i was looking for. Just google'ing why it works now...
>
> Alexandiar gives me a undefined error just using ","
>
> thanks again guys
>
> Kev
>
> "Shay Levi" wrote:
>
Quote:

> > Try:
> >
> >
> > (...)
> > $colResults | foreach {
> > $objItem = $_.Properties
> > $obj = new-object psobject
> > add-member -inp $obj noteproperty name $($objItem.name)
> > add-member -inp $obj noteproperty operatingsystemservicepack $($objItem.operatingsystemservicepack)
> > $obj
> > } | export-csv C:\servers.csv -noType
> >
> >
> >
> > -----
> > Shay Levi
> > $cript Fanatic
> > http://scriptolog.blogspot.com
> >
Quote:

> > > I have the standard ad search script...
> > >
> > > $objDomain = New-Object System.DirectoryServices.DirectoryEntry
> > >
> > > $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
> > > $objSearcher.SearchRoot = $objDomain
> > > #$objSearcher.PageSize = 10000
> > > $objSearcher.Filter = "(&(objectCategory=Computer)
> > > (operatingSystem=*server*))"
> > > $colProplist = "name","operatingsystemservicepack","Created" foreach
> > > ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
> > >
> > > $colResults = $objSearcher.FindAll()
> > >
> > > foreach ($objResult in $colResults)
> > > # {Write $ObjResult.Properties}
> > > {$objItem = $objResult.Properties; $objItem.created;
> > > $objItem.name;
> > > $ObjItem.operatingsystemservicepack}# | export-csv "C:\servers.csv"}
> > > the output gives me
> > >
> > > %Servername%
> > > Service Pack 1
> > > %Servername%
> > > Service Pack 2
> > > How can I alter the output to %Servername% , Service Pack 1
> > >
> > > I have tried adding things along the line of.....
> > >
> > > + "," + but does not seem to work.
> > >
> > > Many thanks
> > >
> > > Kev
> > >
> >
> >
> >
My System SpecsSystem Spec
Old 01-31-2008   #6 (permalink)
Shay Levi
Guest


 

Re: formatting AD output



Hi Kev

Doe's this helps?


#### test.ps1 ###

$filter="(&(objectClass={0})" -f $args[0]

for($i=1; $i -lt $args.count; $i+=2){
$filter+="({0}={1})" -f $args[$i],$args[$i+1]
}

$filter

#################


run the script:

PS > .\args.ps1 "arg1" "one" 1 "two" 2 "three" 3

(&(objectClass=arg1)(one=1)(two=2)(three=3)


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Hi Shay,
>
> I have a similar problem as Kev howerver I'm passing arguments from
> the commandline so I can use the AD search script as a function in my
> profile. I have got as far as finding a quick fix that transposes the
> results to coloumns but i can only get it to work with two arguments
> as the hash table is (2*2). I need it to work with x number of
> arguments or at least 3*3. Please could you show me (or point me in
> the right direction) to modify the following already plagerised
> snippet.
>
> CODE TO TRANSPOSE OUTPUT :
> $list = 1,one,2,two,3,three
> $hash = @{} ; while ($list) { $key, $value, $list = $list;
> $hash[$key]=$value }
> gives output
> 1 one
> 2 two
> 3 three
> 4 four
> FUNCTION :
>
> Function adsmore
> {
> $argument0 = $args[0]
> $argument1 = $args[1]
> $argument2 = $args[2]
> $argument3 = $args[3]
> $argument4 = $args[4]
> $dom =
> [System.DirectoryServices.ActiveDirectory.Domain]::getcurrentdomain().
> name
> #Create New object to search AD
>
> $domain = New-Object DirectoryServices.DirectoryEntry
>
> #Set Search
>
> $search = [System.DirectoryServices.DirectorySearcher]$domain
>
> #Choose Search Filter objectClass "(&(objectCategory=Computer)
>
> (operatingSystem=*Server*))" = servers or replace
> (objectCategory=User),Object=Group .. Etc #So first is the Object type
> or class USER,GROUP,COMPUTER etc, the second is the attribute within
> that objectclass.
>
> $search.Filter =
> "(&(objectClass=$argument0)($argument1=$argument2)($argument3=$argumen
> t4))"
>
> #Go Get it
>
> $user = $search.Findall()
>
> foreach($users in $user){
>
> $Objitem = $users.properties; $objItem.name; $objitem.$argument1;
> $objitem.$argument2; $objitem.$argument3; $objitem.$argument4}
> }
> "Kev T" wrote:
>
Quote:

>> Shay,
>>
>> superb
>>
>> thank you, just what i was looking for. Just google'ing why it works
>> now...
>>
>> Alexandiar gives me a undefined error just using ","
>>
>> thanks again guys
>>
>> Kev
>>
>> "Shay Levi" wrote:
>>
Quote:

>>> Try:
>>>
>>> (...)
>>> $colResults | foreach {
>>> $objItem = $_.Properties
>>> $obj = new-object psobject
>>> add-member -inp $obj noteproperty name $($objItem.name)
>>> add-member -inp $obj noteproperty operatingsystemservicepack
>>> $($objItem.operatingsystemservicepack)
>>> $obj
>>> } | export-csv C:\servers.csv -noType
>>> -----
>>> Shay Levi
>>> $cript Fanatic
>>> http://scriptolog.blogspot.com
>>>> I have the standard ad search script...
>>>>
>>>> $objDomain = New-Object System.DirectoryServices.DirectoryEntry
>>>>
>>>> $objSearcher = New-Object
>>>> System.DirectoryServices.DirectorySearcher
>>>> $objSearcher.SearchRoot = $objDomain
>>>> #$objSearcher.PageSize = 10000
>>>> $objSearcher.Filter = "(&(objectCategory=Computer)
>>>> (operatingSystem=*server*))"
>>>> $colProplist = "name","operatingsystemservicepack","Created"
>>>> foreach
>>>> ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
>>>> $colResults = $objSearcher.FindAll()
>>>>
>>>> foreach ($objResult in $colResults)
>>>> # {Write $ObjResult.Properties}
>>>> {$objItem = $objResult.Properties; $objItem.created;
>>>> $objItem.name;
>>>> $ObjItem.operatingsystemservicepack}# | export-csv
>>>> "C:\servers.csv"}
>>>> the output gives me
>>>> %Servername%
>>>> Service Pack 1
>>>> %Servername%
>>>> Service Pack 2
>>>> How can I alter the output to %Servername% , Service Pack 1
>>>> I have tried adding things along the line of.....
>>>>
>>>> + "," + but does not seem to work.
>>>>
>>>> Many thanks
>>>>
>>>> Kev
>>>>

My System SpecsSystem Spec
Old 01-31-2008   #7 (permalink)
Shay Levi
Guest


 

Re: formatting AD output

The closing LDAP parenthesis is missing



$filter="(&(objectClass={0})" -f $args[0]

for($i=1; $i -lt $args.count; $i+=2){
$filter+="({0}={1})" -f $args[$i],$args[$i+1]
}

$filter+=")"

$filter


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Hi Kev
>
> Doe's this helps?
>
> #### test.ps1 ###
>
> $filter="(&(objectClass={0})" -f $args[0]
>
> for($i=1; $i -lt $args.count; $i+=2){
> $filter+="({0}={1})" -f $args[$i],$args[$i+1]
> }
> $filter
>
> #################
>
> run the script:
>
PS>> .\args.ps1 "arg1" "one" 1 "two" 2 "three" 3
PS>>
Quote:

> (&(objectClass=arg1)(one=1)(two=2)(three=3)
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
Quote:

>> Hi Shay,
>>
>> I have a similar problem as Kev howerver I'm passing arguments from
>> the commandline so I can use the AD search script as a function in my
>> profile. I have got as far as finding a quick fix that transposes the
>> results to coloumns but i can only get it to work with two arguments
>> as the hash table is (2*2). I need it to work with x number of
>> arguments or at least 3*3. Please could you show me (or point me in
>> the right direction) to modify the following already plagerised
>> snippet.
>>
>> CODE TO TRANSPOSE OUTPUT :
>> $list = 1,one,2,two,3,three
>> $hash = @{} ; while ($list) { $key, $value, $list = $list;
>> $hash[$key]=$value }
>> gives output
>> 1 one
>> 2 two
>> 3 three
>> 4 four
>> FUNCTION :
>> Function adsmore
>> {
>> $argument0 = $args[0]
>> $argument1 = $args[1]
>> $argument2 = $args[2]
>> $argument3 = $args[3]
>> $argument4 = $args[4]
>> $dom =
>> [System.DirectoryServices.ActiveDirectory.Domain]::getcurrentdomain()
>> .
>> name
>> #Create New object to search AD
>> $domain = New-Object DirectoryServices.DirectoryEntry
>>
>> #Set Search
>>
>> $search = [System.DirectoryServices.DirectorySearcher]$domain
>>
>> #Choose Search Filter objectClass "(&(objectCategory=Computer)
>>
>> (operatingSystem=*Server*))" = servers or replace
>> (objectCategory=User),Object=Group .. Etc #So first is the Object
>> type or class USER,GROUP,COMPUTER etc, the second is the attribute
>> within that objectclass.
>>
>> $search.Filter =
>> "(&(objectClass=$argument0)($argument1=$argument2)($argument3=$argume
>> n t4))"
>>
>> #Go Get it
>>
>> $user = $search.Findall()
>>
>> foreach($users in $user){
>>
>> $Objitem = $users.properties; $objItem.name; $objitem.$argument1;
>> $objitem.$argument2; $objitem.$argument3; $objitem.$argument4}
>> }
>> "Kev T" wrote:
Quote:

>>> Shay,
>>>
>>> superb
>>>
>>> thank you, just what i was looking for. Just google'ing why it works
>>> now...
>>>
>>> Alexandiar gives me a undefined error just using ","
>>>
>>> thanks again guys
>>>
>>> Kev
>>>
>>> "Shay Levi" wrote:
>>>
>>>> Try:
>>>>
>>>> (...)
>>>> $colResults | foreach {
>>>> $objItem = $_.Properties
>>>> $obj = new-object psobject
>>>> add-member -inp $obj noteproperty name $($objItem.name)
>>>> add-member -inp $obj noteproperty operatingsystemservicepack
>>>> $($objItem.operatingsystemservicepack)
>>>> $obj
>>>> } | export-csv C:\servers.csv -noType
>>>> -----
>>>> Shay Levi
>>>> $cript Fanatic
>>>> http://scriptolog.blogspot.com
>>>>> I have the standard ad search script...
>>>>>
>>>>> $objDomain = New-Object System.DirectoryServices.DirectoryEntry
>>>>>
>>>>> $objSearcher = New-Object
>>>>> System.DirectoryServices.DirectorySearcher
>>>>> $objSearcher.SearchRoot = $objDomain
>>>>> #$objSearcher.PageSize = 10000
>>>>> $objSearcher.Filter = "(&(objectCategory=Computer)
>>>>> (operatingSystem=*server*))"
>>>>> $colProplist = "name","operatingsystemservicepack","Created"
>>>>> foreach
>>>>> ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
>>>>> $colResults = $objSearcher.FindAll()
>>>>> foreach ($objResult in $colResults)
>>>>> # {Write $ObjResult.Properties}
>>>>> {$objItem = $objResult.Properties; $objItem.created;
>>>>> $objItem.name;
>>>>> $ObjItem.operatingsystemservicepack}# | export-csv
>>>>> "C:\servers.csv"}
>>>>> the output gives me
>>>>> %Servername%
>>>>> Service Pack 1
>>>>> %Servername%
>>>>> Service Pack 2
>>>>> How can I alter the output to %Servername% , Service Pack 1
>>>>> I have tried adding things along the line of.....
>>>>> + "," + but does not seem to work.
>>>>>
>>>>> Many thanks
>>>>>
>>>>> Kev
>>>>>

My System SpecsSystem Spec
Old 01-31-2008   #8 (permalink)
Server Bitch
Guest


 

Re: formatting AD output

Hi Shay,

Sorry misunderstanding - I need the OUTPUT re formatted from a list to
columns.....

I had already got the arguments working correctly within the LDAP query
however your way is much better if the LDAP can handle grabbing the args
directly from the command line - I had problems hence the $argument0 =
$arg[0] polava!

What I'm after is the outputted list of args to be reformatted to produce a
table of columns.

- note for each AD Object returned there are 3 properties that echo out,
currently the default output is a list - I would like to transpose them. The
following will transpose an object with two properties returned but not three
- or more - hence the post!
$list = blah blah
$hash = @{} ; while ($list) { $key, $value, $list = $list;
$hash[$key]=$value }



EG

..\adsmore.ps1 arg1 arg2 arg3 arg4 arg5


gives this output in the shell

$objItem.name
$objitem.$argument2
$objitem.$argument4
$objItem.name
$objitem.$argument2
$objitem.$argument4
$objItem.name
$objitem.$argument2
$objitem.$argument4
etc

I need the output to then be transposed to

$objItem.name $objitem.$argument2 $objitem.$argument4
$objItem.name $objitem.$argument2 $objitem.$argument4
$objItem.name $objitem.$argument2 $objitem.$argument4
$objItem.name $objitem.$argument2 $objitem.$argument4
$objItem.name $objitem.$argument2 $objitem.$argument4
etc




"Shay Levi" wrote:
Quote:

> The closing LDAP parenthesis is missing
>
>
>
> $filter="(&(objectClass={0})" -f $args[0]
>
> for($i=1; $i -lt $args.count; $i+=2){
> $filter+="({0}={1})" -f $args[$i],$args[$i+1]
> }
>
> $filter+=")"
>
> $filter
>
>
> -----
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

> > Hi Kev
> >
> > Doe's this helps?
> >
> > #### test.ps1 ###
> >
> > $filter="(&(objectClass={0})" -f $args[0]
> >
> > for($i=1; $i -lt $args.count; $i+=2){
> > $filter+="({0}={1})" -f $args[$i],$args[$i+1]
> > }
> > $filter
> >
> > #################
> >
> > run the script:
> >
> PS>> .\args.ps1 "arg1" "one" 1 "two" 2 "three" 3
> PS>>
Quote:

> > (&(objectClass=arg1)(one=1)(two=2)(three=3)
> >
> > -----
> > Shay Levi
> > $cript Fanatic
> > http://scriptolog.blogspot.com
Quote:

> >> Hi Shay,
> >>
> >> I have a similar problem as Kev howerver I'm passing arguments from
> >> the commandline so I can use the AD search script as a function in my
> >> profile. I have got as far as finding a quick fix that transposes the
> >> results to coloumns but i can only get it to work with two arguments
> >> as the hash table is (2*2). I need it to work with x number of
> >> arguments or at least 3*3. Please could you show me (or point me in
> >> the right direction) to modify the following already plagerised
> >> snippet.
> >>
> >> CODE TO TRANSPOSE OUTPUT :
> >> $list = 1,one,2,two,3,three
> >> $hash = @{} ; while ($list) { $key, $value, $list = $list;
> >> $hash[$key]=$value }
> >> gives output
> >> 1 one
> >> 2 two
> >> 3 three
> >> 4 four
> >> FUNCTION :
> >> Function adsmore
> >> {
> >> $argument0 = $args[0]
> >> $argument1 = $args[1]
> >> $argument2 = $args[2]
> >> $argument3 = $args[3]
> >> $argument4 = $args[4]
> >> $dom =
> >> [System.DirectoryServices.ActiveDirectory.Domain]::getcurrentdomain()
> >> .
> >> name
> >> #Create New object to search AD
> >> $domain = New-Object DirectoryServices.DirectoryEntry
> >>
> >> #Set Search
> >>
> >> $search = [System.DirectoryServices.DirectorySearcher]$domain
> >>
> >> #Choose Search Filter objectClass "(&(objectCategory=Computer)
> >>
> >> (operatingSystem=*Server*))" = servers or replace
> >> (objectCategory=User),Object=Group .. Etc #So first is the Object
> >> type or class USER,GROUP,COMPUTER etc, the second is the attribute
> >> within that objectclass.
> >>
> >> $search.Filter =
> >> "(&(objectClass=$argument0)($argument1=$argument2)($argument3=$argume
> >> n t4))"
> >>
> >> #Go Get it
> >>
> >> $user = $search.Findall()
> >>
> >> foreach($users in $user){
> >>
> >> $Objitem = $users.properties; $objItem.name;
> >> $objitem.$argument2; $objitem.$argument4}
> >> }
> >> "Kev T" wrote:
> >>> Shay,
> >>>
> >>> superb
> >>>
> >>> thank you, just what i was looking for. Just google'ing why it works
> >>> now...
> >>>
> >>> Alexandiar gives me a undefined error just using ","
> >>>
> >>> thanks again guys
> >>>
> >>> Kev
> >>>
> >>> "Shay Levi" wrote:
> >>>
> >>>> Try:
> >>>>
> >>>> (...)
> >>>> $colResults | foreach {
> >>>> $objItem = $_.Properties
> >>>> $obj = new-object psobject
> >>>> add-member -inp $obj noteproperty name $($objItem.name)
> >>>> add-member -inp $obj noteproperty operatingsystemservicepack
> >>>> $($objItem.operatingsystemservicepack)
> >>>> $obj
> >>>> } | export-csv C:\servers.csv -noType
> >>>> -----
> >>>> Shay Levi
> >>>> $cript Fanatic
> >>>> http://scriptolog.blogspot.com
> >>>>> I have the standard ad search script...
> >>>>>
> >>>>> $objDomain = New-Object System.DirectoryServices.DirectoryEntry
> >>>>>
> >>>>> $objSearcher = New-Object
> >>>>> System.DirectoryServices.DirectorySearcher
> >>>>> $objSearcher.SearchRoot = $objDomain
> >>>>> #$objSearcher.PageSize = 10000
> >>>>> $objSearcher.Filter = "(&(objectCategory=Computer)
> >>>>> (operatingSystem=*server*))"
> >>>>> $colProplist = "name","operatingsystemservicepack","Created"
> >>>>> foreach
> >>>>> ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
> >>>>> $colResults = $objSearcher.FindAll()
> >>>>> foreach ($objResult in $colResults)
> >>>>> # {Write $ObjResult.Properties}
> >>>>> {$objItem = $objResult.Properties; $objItem.created;
> >>>>> $objItem.name;
> >>>>> $ObjItem.operatingsystemservicepack}# | export-csv
> >>>>> "C:\servers.csv"}
> >>>>> the output gives me
> >>>>> %Servername%
> >>>>> Service Pack 1
> >>>>> %Servername%
> >>>>> Service Pack 2
> >>>>> How can I alter the output to %Servername% , Service Pack 1
> >>>>> I have tried adding things along the line of.....
> >>>>> + "," + but does not seem to work.
> >>>>>
> >>>>> Many thanks
> >>>>>
> >>>>> Kev
> >>>>>
>
>
>
My System SpecsSystem Spec
Old 02-01-2008   #9 (permalink)
Shay Levi
Guest


 

Re: formatting AD output

If I get you now
You can build a custom object and the send it to format-table


$obj = new-object psobject
add-member -inp $obj noteproperty name $objItem.name
add-member -inp $obj noteproperty argument2 $objItem.$argument2
add-member -inp $obj noteproperty argument4 $objItem.$argument4
$obj


It should be formatted to the console as:

name argument2 argument4
----- ---------- ----------
val val val
val val val
val val val
(...)



If I didn't follow you this time too, plz post your complete script.




-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Quote:

> Hi Shay,
>
> Sorry misunderstanding - I need the OUTPUT re formatted from a list to
> columns.....
>
> I had already got the arguments working correctly within the LDAP
> query however your way is much better if the LDAP can handle grabbing
> the args directly from the command line - I had problems hence the
> $argument0 = $arg[0] polava!
>
> What I'm after is the outputted list of args to be reformatted to
> produce a table of columns.
>
> - note for each AD Object returned there are 3 properties that echo
> out,
> currently the default output is a list - I would like to transpose
> them. The
> following will transpose an object with two properties returned but
> not three
> - or more - hence the post!
> $list = blah blah
> $hash = @{} ; while ($list) { $key, $value, $list = $list;
> $has