gpt4 book ai didi

powershell - PSCustomObject 到哈希表

转载 作者:行者123 更新时间:2023-12-03 05:32:09 25 4
gpt4 key购买 nike

PSCustomObject 转换为 Hashtable 的最简单方法是什么?它的显示方式就像带有 splat 运算符、花括号和看似键值对的内容一样。当我尝试将其转换为 [Hashtable] 时,它不起作用。我还尝试了 .toString() ,分配的变量说它是一个字符串,但什么也不显示 - 有什么想法吗?

最佳答案

应该不会太难。像这样的事情应该可以解决问题:

# Create a PSCustomObject (ironically using a hashtable)
$ht1 = @{ A = 'a'; B = 'b'; DateTime = Get-Date }
$theObject = new-object psobject -Property $ht1

# Convert the PSCustomObject back to a hashtable
$ht2 = @{}
$theObject.psobject.properties | Foreach { $ht2[$_.Name] = $_.Value }

关于powershell - PSCustomObject 到哈希表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3740128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com