ServiceNow的Powershell SOAP

Cla*_*ton 2 powershell soap servicenow

我正在尝试使用Powershell SOAP在ServiceNow中创建一个票证.我使用基本身份验证使用SoapUI工具成功测试了有效的XML.但是当我尝试通过Powershell将相同的XML发布到ServiceNow时,我得到一个错误.我不确定它是否与auth标头有问题(在SoapUI和PS中都有相同的信誉)或其他因为我从帖子中得到500错误,这听起来与auth无关.

使用PS v4.很长一段时间PowerShell用户.第一次使用ServiceNow进行SOAP和脚本交互.他们的wiki没有强大的例子:(
谢谢

$uri = "https://fubar.service-now.com/u_smarts_notification.do?SOAP"
$username = 'looseLips'
$password = 'sinkShips'

$xml = [xml]@"
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://www.service-now.com/u_smarts_notification">
   <soapenv:Header/>
   <soapenv:Body>
      <u:insert>
         <u_assignment_group>Some Group</u_assignment_group>
         <u_impact>4</u_impact>
         <u_urgency>3</u_urgency>
         <u_op_tier_1>Malfunction</u_op_tier_1>
         <u_op_tier_2>Error</u_op_tier_2>
         <u_op_tier_3>Break Fix</u_op_tier_3>
         <u_short_description>Subject</u_short_description>
         <u_work_notes>Body</u_work_notes>
      </u:insert>
   </soapenv:Body>
</soapenv:Envelope>
"@

$header = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($username+":"+$password))}
$post = Invoke-WebRequest -Uri $uri -Headers $header -Method Post -Body $xml



Invoke-WebRequest : The remote server returned an error: (500) Internal Server
Error.
At R:\ps1\serviceNowINC.ps1:30 char:9
+ $post = Invoke-WebRequest -Uri $uri -Headers $header -Method Post -Body $xml
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:Htt
   pWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe
   ll.Commands.InvokeWebRequestCommand
Run Code Online (Sandbox Code Playgroud)

Moh*_*eem 5

尝试设置内容类型

$post = Invoke-WebRequest -Uri $uri -Headers $header -Method Post -Body $xml -ContentType "application/xml"
Run Code Online (Sandbox Code Playgroud)