我有在Azure上运行的Runbook。我得到的数据类型为 System.Collections.Generic.Dictionary`2 [System.String,System.String] ,但是我需要将其转换为 System.Collections.Hashtable

我使用C#找到了一个example,但是如何使用Power Shell来实现呢?

换句话说,在我的场景中,我需要将字典类型转换为哈希表。

最佳答案

PowerShell中的C#答案很简单:

Write-Host "....dictionary"
$d = [System.Collections.Generic.Dictionary`2[System.String,System.String]]::new()  # `
$d.Add("one", "111")
$d.Add("two", "222")
Write-Host "$d"
$d | ft

Write-Host "....hashtable"
$h = [System.Collections.Hashtable]::new($d)
Write-Host "$h"
$h | ft

关于powershell - PowerShell将字典转换为哈希表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48679157/

10-09 17:54
查看更多