Iterate Generic List of Strings (Lync chatroom members) in Powershell

让人想犯罪 __ 提交于 2019-12-11 11:21:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!