Property passed to Invoke-Command changes type from IDictionary to HashTable

跟風遠走 提交于 2019-12-03 20:45:52

This is a known problem with the deserialization code that is involved in PowerShell remoting (which is what Invoke-Command -ComputerName is based on), unfortunately, as of PowerShell Core 7.0.0-preview.2:

On deserialization, any object that implements the IDictionary interface is incorrectly assumed to always be a regular, non-generic [hashtable][1] and deserialized as such.

This is especially problematic when the original object was an ordered dictionary[2], because the ordering of the keys is lost, as is the ability to index into them.

See this GitHub issue, which is tagged as "up for grabs", meaning that the community is free to offer a PR that fixes the problem.


[1] System.Collections.Hashtable, creatable in PowerShell with @{ ... } literals, where both the keys and values are [object]-typed.

[2] E.g., System.Collections.Specialized.OrderedDictionary, creatable in PowerShell with [ordered] @{ ... } literals, also with [object]-typed keys and values (non-generic); suprisingly, as of this writing, there is no generic ordered dictionary type - see this question.

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