我试图在售票系统的API上使用PowerShell Invoke-RestMethod
,然后将输出转换为PowerShell对象。将Invoke-RestMethod输出转换为对象
作为一个例子,当我使用Invoke-RestMethod
来获得票的属性,我得到了这个。
$object = Invoke-RestMethod '[URI here]'
$object.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
$object
EWREST_supported_user0='Yes';
EWREST_updater_team='Support Team';
EWREST_eng_id='CLT';
EWREST_testlabelsub='Test Label';
EWREST_time_created='17:21:03';
EWREST_cr_conversion_related_to='Support Case';
EWREST__1901_full_name='secuser Testuser1';
EWREST_summary='Ticket Title';
EWREST_i_would_like_to_reopen_my_ticket='No';
EWREST_assigned_team_leader='Agiloft Admin';
EWREST_id='183255';
EWREST_severity='Sev 4';
EWREST_problem_description='<div>This is an example of a ticket note that takes up multiple lines when read via API<\/div><div> <\/div><div>Example note info here<\/div><div> <\/div>
<div>Additional example note info here<\/div><div> <\/div><div>Even more note info here<\/div>';
EWREST_demo_data='No';
我想做什么就能做的是做这样的事情$object.EWREST_category
操纵$object
作为一个对象,并获得“网络”。所以我一直在试图弄清楚如何将maniuplate $object
这只是一个属性的字符串传递给具有属性的传统PowerShell对象。
有人可以提供一些关于如何去做?
谢谢,这看起来像它会适合我。我确实有一个问题,其中一个属性是多行属性。这似乎打破了ConvertFrom-StringData命令。即在第一个新行上它获得“数据线新行在行:3字符44不是名称=值格式”任何想法如何防止? – floyd
这取决于实际数据的样子。请更新您问题中的示例。 –
我在我的问题中更新了示例以包含属性EWREST_problem_description,该属性是多行,并导致ConvertFrom-StringData命令出现问题。当它到达该属性的第二行时,它不会将其视为name = value格式。 – floyd