![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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: 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||