Link to home
Start Free TrialLog in
Avatar of Michael Leonard
Michael LeonardFlag for United States of America

asked on

powershell question need assistance

can someone provide a way that we can list all the members of all persistant chat rooms adding a variable to the following script:

this script works fine for one room at a time, we have over 100

Get-CsPersistentChatRoom -Identity <Room Name> | select-object members

Open in new window

Avatar of oBdA
oBdA

Assuming you have a file with a list of those names, it's just a matter of a ForEach loop.
This will add the room name to the output, so that you'll be able to actually see which room has which members.
Get-Content -Path C:\Temp\roomlist.txt | ForEach-Object {
	$Room = $_
	Get-CsPersistentChatRoom -Identity $Room |
		Select-Object @{n='Room'; e={$Room}}, Members
}

Open in new window

Avatar of Michael Leonard

ASKER

thanks oBda - what is the best way to export the results to csv?
The Export-Csv cmdlet:
Get-Content -Path C:\Temp\roomlist.txt | ForEach-Object {
	$Room = $_
	Get-CsPersistentChatRoom -Identity <Room Name> |
		Select-Object @{n='Room'; e={$Room}}, Members
} | Export-Csv -NoTypeInformation -Path C:\Temp\rooms.csv

Open in new window

hi oBda,  here is what I'm seeing in the output file [no members]

Room","Members"
"room1","System.Collections.Generic.List`1[System.String]"
"room2","System.Collections.Generic.List`1[System.String]"
"room3","System.Collections.Generic.List`1[System.String]"

Open in new window

Sorry, can't test this, but this should expand the list:
Get-Content -Path C:\Temp\roomlist.txt | ForEach-Object {
	$Room = $_
	Get-CsPersistentChatRoom -Identity <Room Name> |
		Select-Object @{n='Room'; e={$Room}}, @{n='Members'; e={$_.Members -join '; '}}
}

Open in new window

here is what i'm seeing when running:

+     Get-CsPersistentChatRoom -Identity <Room Name> |
+                                        ~
The '<' operator is reserved for future use.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : RedirectionNotSupported

Open in new window


also we need this exported out to csv.  thx
My bad, copy and paste error:
Get-Content -Path C:\Temp\roomlist.txt | ForEach-Object {
	$Room = $_
	Get-CsPersistentChatRoom -Identity <Room Name> |
		Select-Object @{n='Room'; e={$Room}}, @{n='Members'; e={$_.Members -join '; '}}
} | Export-Csv -NoTypeInformation -Path C:\Temp\rooms.csv 

Open in new window

still seeing this error when running:

At C:\Users\admin\Desktop\export-rooms.ps1:3 char:37
+     Get-CsPersistentChatRoom -Identity <Room Name> |
+                                        ~
The '<' operator is reserved for future use.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : RedirectionNotSupported

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
great thanks oBDA worked perfectly