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

output group membership on a single line

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 05-22-2008   #1 (permalink)
Steven
Guest


 

output group membership on a single line

I've been trying to figure out how to do this and I just can't seem to
figure it out. What I have is this:

(get-group -Identity <groupName>).members | select name

This returns each name on a separate line:

User1
User2
User3
User4

What I'd like is to change it to a series of strings that I can save to
a file where it looks like this:

User1,User2,User3,User4

Any thoughts on how to do this?

As always thanks for any answers or feedback.

My System SpecsSystem Spec
Old 05-22-2008   #2 (permalink)
Steven
Guest


 

Re: output group membership on a single line

Perfect..thanks!

Shay Levi wrote:
Quote:

>
>
> Hi Steven,
>
> First strip the object to have the names (group members) as strings
> only, use foreach instead of select, and assign it to a variable. Here's
> an example using get-process:
>
> PS 22> $names = gps m* | foreach {$_.name}
> PS 23> $names
> Maxthon
> mDNSResponder
> msdtc
> msnmsgr
> mstsc
>
> In PowerShell v1.0 you can join the strings with [string]::join static
> method:
>
>
> PS 24> [string]::join(",",$names)
>
> Maxthon,mDNSResponder,msdtc,msnmsgr,mstsc
>
>
> PowerShell CTP(2) has a new -join parameter, so you can do:
>
> PS 25> $p -join ","
> Maxthon,mDNSResponder,msdtc,msnmsgr,mstsc
>
>
>
> ---
> Shay Levi
> $cript Fanatic
> http://scriptolog.blogspot.com
>
Quote:

>> I've been trying to figure out how to do this and I just can't seem
>> to figure it out. What I have is this:
>>
>> (get-group -Identity <groupName>).members | select name
>>
>> This returns each name on a separate line:
>>
>> User1
>> User2
>> User3
>> User4
>> What I'd like is to change it to a series of strings that I can save
>> to a file where it looks like this:
>>
>> User1,User2,User3,User4
>>
>> Any thoughts on how to do this?
>>
>> As always thanks for any answers or feedback.
>>
>
>
My System SpecsSystem Spec
Old 05-22-2008   #3 (permalink)
Shay Levi
Guest


 

Re: output group membership on a single line



Hi Steven,

First strip the object to have the names (group members) as strings only,
use foreach instead of select, and assign it to a variable.
Here's an example using get-process:

PS 22> $names = gps m* | foreach {$_.name}
PS 23> $names

Maxthon
mDNSResponder
msdtc
msnmsgr
mstsc

In PowerShell v1.0 you can join the strings with [string]::join static method:


PS 24> [string]::join(",",$names)

Maxthon,mDNSResponder,msdtc,msnmsgr,mstsc


PowerShell CTP(2) has a new -join parameter, so you can do:

PS 25> $p -join ","
Maxthon,mDNSResponder,msdtc,msnmsgr,mstsc



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

> I've been trying to figure out how to do this and I just can't seem
> to figure it out. What I have is this:
>
> (get-group -Identity <groupName>).members | select name
>
> This returns each name on a separate line:
>
> User1
> User2
> User3
> User4
> What I'd like is to change it to a series of strings that I can save
> to a file where it looks like this:
>
> User1,User2,User3,User4
>
> Any thoughts on how to do this?
>
> As always thanks for any answers or feedback.
>

My System SpecsSystem Spec
Old 05-22-2008   #4 (permalink)
alexandair
Guest


 

Re: output group membership on a single line

Hi Steven,

Here is a nice one-liner for you. :-)

(get-qadgroup -Identity <groupName>) | get-qadgroupmember |
% {$names = @()} {$names += $_.name} {[string]::join(",",$names)} |
out-file c:\temp\members.txt

-aleksandar
http://powershellers.blogpost.com


On May 22, 8:37*pm, Steven <evetsl...@xxxxxx> wrote:
Quote:

> Perfect..thanks!
>
>
>
> Shay Levi wrote:
>
Quote:

> > Hi Steven,
>
Quote:

> > First strip the object to have the names (group members) as strings
> > only, use foreach instead of select, and assign it to a variable. Here's
> > an example using get-process:
>
Quote:

> > PS 22> $names = gps m* | foreach {$_.name}
> > PS 23> $names
> > Maxthon
> > mDNSResponder
> > msdtc
> > msnmsgr
> > mstsc
>
Quote:

> > In PowerShell v1.0 you can join the strings with [string]::join static
> > method:
>
Quote:

> > PS 24> [string]::join(",",$names)
>
Quote:

> > Maxthon,mDNSResponder,msdtc,msnmsgr,mstsc
>
Quote:

> > PowerShell CTP(2) has a new -join parameter, so you can do:
>
Quote:

> > PS 25> $p -join ","
> > Maxthon,mDNSResponder,msdtc,msnmsgr,mstsc
>
Quote:

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

> >> I've been trying to figure out how to do this and I just can't seem
> >> to figure it out. *What I have is this:
>
Quote:
Quote:

> >> (get-group -Identity <groupName>).members | select name
>
Quote:
Quote:

> >> This returns each name on a separate line:
>
Quote:
Quote:

> >> User1
> >> User2
> >> User3
> >> User4
> >> What I'd like is to change it to a series of strings that I can save
> >> to a file where it looks like this:
>
Quote:
Quote:

> >> User1,User2,User3,User4
>
Quote:
Quote:

> >> Any thoughts on how to do this?
>
Quote:
Quote:

> >> As always thanks for any answers or feedback.- Hide quoted text -
>
> - Show quoted text -
My System SpecsSystem Spec
Old 05-27-2008   #5 (permalink)
Tibor Soos
Guest


 

RE: output group membership on a single line

What about this?

[PS] C:\>[string] ((get-group -Identity Legal).members | ForEach-Object
{$_.name})
Kim Akers Brian Cox


--
Tibor


"Steven" wrote:
Quote:

> I've been trying to figure out how to do this and I just can't seem to
> figure it out. What I have is this:
>
> (get-group -Identity <groupName>).members | select name
>
> This returns each name on a separate line:
>
> User1
> User2
> User3
> User4
>
> What I'd like is to change it to a series of strings that I can save to
> a file where it looks like this:
>
> User1,User2,User3,User4
>
> Any thoughts on how to do this?
>
> As always thanks for any answers or feedback.
>
My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get group membership David Arro PowerShell 2 08-31-2008 10:47 AM
Get Group Membership for a User LE2 Strat PowerShell 4 01-31-2008 08:16 AM
Group Membership Don D Vista mail 0 09-15-2007 09:31 AM
ADSI and group membership - what am I doing wrong Neil Chambers PowerShell 5 07-14-2007 04:36 AM
Enumerating group membership & ADSI CrazyKiwi PowerShell 7 07-05-2007 07:42 PM


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