0

我有这段代码在 ServiceNow 中创建一个新票

$Response = Invoke-RestMethod -Uri $URI  -Credential $SNowCreds -Method Post -Body $body -ContentType 'application/xml' 
Write-IntoLog $Response.result

输出存储在$Response中,如下所示

@{parent=; made_sla=true; caused_by=; watch_list=; upon_reject=Cancel all future Tasks; sys_updated_on=2018-01-11 08:49:50; child_incidents=0; hold_reason=; approval_history=; number=INC0010079; resolved_by=; sys_updated_by=Admin; opened_by=; user_input=; sys_created_on=2018-01-11 08:49:50; sys_domain=; state=In Progress; sys_created_by=Admin; knowledge=false; order=; calendar_stc=; closed_at=; cmdb_ci=; delivery_plan=; impact=2 - Medium; active=true; work_notes_list=; business_service=; priority=2 - High; sys_domain_path=/; rfc=; time_worked=; expected_start=; opened_at=2018-01-11 08:49:50; business_duration=; group_list=; work_end=; caller_id=; reopened_time=; resolved_at=; approval_set=; subcategory=Internal Application; work_notes=; short_description=Issues with Accessing Web URL; close_code=; correlation_display=; delivery_task=; work_start=; assignment_group=; additional_assignee_list=; business_stc=; description=We are facing issues with accessing the portal https://www.inmotion.com. The error Received is a 403 Error and Access to the same; calendar_duration=; close_notes=; notify=Do Not Notify; sys_class_name=Incident; closed_by=; follow_up=; parent_incident=; sys_id=2c40df9edb234300479a7e7dbf96198f; contact_type=; reopened_by=; incident_state=In Progress; urgency=1 - High; problem_id=; company=; reassignment_count=0; activity_due=UNKNOWN; assigned_to=; severity=3 - Low; comments=; approval=Not Yet Requested; sla_due=UNKNOWN; comments_and_work_notes=; due_date=; sys_mod_count=0; reopen_count=0; sys_tags=; escalation=Normal; upon_approval=Proceed to Next Task; correlation_id=; location=; category=Network}

我想从输出中提取数字(事件 ID)并生成指向 ServiceNow 事件的链接。

但是我无法提取号码(事件 ID)。我尝试将输出片段转换为 JSON

$Response = Invoke-RestMethod -Uri $URI  -Credential $SNowCreds -Method Post -Body $body -ContentType 'application/xml' | ConvertTo-Json

我试图通过节点导航它。我仍然无法检索IncidentID 请求您就上述问题提供帮助。

4

1 回答 1

0

不使用“ConvertTo-Json”

 Write-host "The number is  $($response.result.number)"

这行得通。

其他有用的参考:Powershell ServiceNow API

于 2018-01-12T14:12:04.480 回答