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 - output group membership on a single line

Reply
 
Old 05-22-2008   #1 (permalink)
Steven


 
 

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


 
 

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


 
 

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


 
 

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


 
 

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
Reply

Thread Tools


Similar Threads
Thread Forum
Output XML to Single Line Log File using VBScript VB Script
check group membership PowerShell
Get group membership PowerShell
Get Group Membership for a User PowerShell
Group Membership Vista mail


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