【发布时间】:2021-04-01 16:14:48
【问题描述】:
我认为这与它通过 azure 自动化有关...
这是我正在做的事情:
$tBody = @{
'caller'=$caller # this is just a string 'something@something.com'
'pscustomobject' = $pscustomobject # this is a pscustom object
}
$passToAction = [pscustomobject]@{
paramblock = $paramBlock # this is a pscustom object and one of the objects is another pscustomobject called pscustomobject which is a pscustomobject that was convertto-csv -notypeinformation converted
}
$passToActionJSON = $passToAction| ConvertTo-Json -Depth 99
另一方面,长话短说......我尽我所能做 converfrom-json。但我最终得到一个看起来像这样的字符串:
$b.paramblock.pscustomobject
@{TimeGenerated=2020-12-22T23:22:17.527Z; protocol=Kerberos; AuthServer=stuff; IpAddress=suff; NonExistentUser=stuff; TargetDomainName=
stuff; vmName=stuff}
@{TimeGenerated=2020-12-22T23:22:17.527Z; protocol=Kerberos; AuthServer=stuff; IpAddress=suff; NonExistentUser=stuff; TargetDomainName=
stuff; vmName=stuff}
@{TimeGenerated=2020-12-22T23:22:17.527Z; protocol=Kerberos; AuthServer=stuff; IpAddress=suff; NonExistentUser=stuff; TargetDomainName=
stuff; vmName=stuff}
有人知道如何将其转变成可用的东西吗?我真正想要的是它回到一个 pscustomobject 中。如果您有更好的方法来发送它,但我在 azure 自动化中工作,所以不承诺任何 .net 类在那里。
【问题讨论】:
-
相当混乱...
$b是什么?$tbody去哪儿了?尝试在您的问题中构建minimal reproducible example。另见:how to ask a good question -
无论如何要了解您的 PowerShell 表达式应该如何构建您的特定 json 字符串,试试这个
$Object = ConvertFrom-Json $Json(-AsHashTable) 而不是ConvertTo-Expression $Object -
没有显示所有未定义变量的来源以及它们应该包含的内容,我非常怀疑任何人都能够给你一个答案..
-
(同意上面的cmets)..什么是
$caller变量类型和值?$pscustomobject变量类型和值是什么?$paramBlock变量类型和值是什么?您的“另一面”看起来像 [PSCustomObject] 数组,但您的示例显示没有使用TimeGenerated、protocol、AuthServer、IpAddress或vmName属性分配或声明。
标签: .net azure powershell automation