PowerShell 将 PSCUSTOM 对象传递给 json
PowerShell Passing PSCUSTOM object to json
我认为这与它通过 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
另一方面长话短说....我尽可能多地转换-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 automation 中工作,所以不承诺任何 .net class 在那里。
这是我的工作流程
-> $pscustomobject =
--> something = something
--> something2 = ($pscustomobject | convertto-json)
--> something3 = something3
-> $newpscustomobject =
--> paramblock = $pscustomobject
-> $newpscustomobject | convertto-json -depth 99
这把它变成了普通垃圾
长话短说,将每个 pscustomobject 保持在两个级别,否则 powershell 将其提升
$paramBlock = @()
$paramBlock = [pscustomobject]@{
ticket_body = $ticket_body
ticket_short_description = $subject
category = 'stuff'
subcategory = 'Other'
assignment_group = 'stuff'
csvname = 'stuff.csv'
location = 'waco'
}
$passToAction = [pscustomobject]@{
paramblock = $paramBlock # pscustomobject
csvattachment = $eventsQueryResults #pscustomobject
}
$passToActionJson = $passToAction | ConvertTo-Json -Depth 99
Invoke-AutomationWatcherAction -Message $subject -Data $passToActionJson
我认为这与它通过 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
另一方面长话短说....我尽可能多地转换-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 automation 中工作,所以不承诺任何 .net class 在那里。
这是我的工作流程
-> $pscustomobject =
--> something = something
--> something2 = ($pscustomobject | convertto-json)
--> something3 = something3
-> $newpscustomobject =
--> paramblock = $pscustomobject
-> $newpscustomobject | convertto-json -depth 99
这把它变成了普通垃圾
长话短说,将每个 pscustomobject 保持在两个级别,否则 powershell 将其提升
$paramBlock = @()
$paramBlock = [pscustomobject]@{
ticket_body = $ticket_body
ticket_short_description = $subject
category = 'stuff'
subcategory = 'Other'
assignment_group = 'stuff'
csvname = 'stuff.csv'
location = 'waco'
}
$passToAction = [pscustomobject]@{
paramblock = $paramBlock # pscustomobject
csvattachment = $eventsQueryResults #pscustomobject
}
$passToActionJson = $passToAction | ConvertTo-Json -Depth 99
Invoke-AutomationWatcherAction -Message $subject -Data $passToActionJson