问题
I can't iterate through a Generic List of Strings in Powershell. The Object is the members of a Lync chatroom. Command to get the Generic List:
$crMembers = get-csPersistentChatroom -identity "XXXX" | select members
The error I receive when trying to read the Strings in the Generic List is:
WARNING: An error ocurred: Cannot convert value
"@{Members=System.Collections.Generic.List`1[System.String]}" to type
"System.Collections.Generic.List`1[System.String]". Error: "Cannot convert the
"@{Members=System.Collections.Generic.List`1[System.String]}" value of type
"Selected.Microsoft.Rtc.Management.Chat.Cmdlets.ChatRoom" to type
"System.Collections.Generic.List`1[System.String]"."
I have also tried this without success:
foreach ($Member in $crMembers.GetEnumerator())
{
Write-Host $Member
}
How can I iterate a "@{Members=System.Collections.Generic.List`1[System.String]}" without errors?
回答1:
Your list is a property of the $crMembers object, called "Members", so
Foreach ($Member in $crMembers.Members)
{...}
来源:https://stackoverflow.com/questions/30099674/iterate-generic-list-of-strings-lync-chatroom-members-in-powershell