An example of creating an incident via Web Services using Powershell

Version 2
    Share This:

    Perhaps others will find this useful.  Otherwise, this is a way for me to recall the syntax when I need it later on :-) ...

     

    Here's an example of creating an Incident using the Create_Incident method, via Powershell.  I believe you'll need Powershell version 3 or 4, in order to have the Invoke-WebRequest method (as far as I recall).  If you have an earlier version of Powershell, you'll need to use another method to invoke the soap request.

     

    Just modify the first line to have your midtier and arserver hostnames and port.  If necessary, modify the username and password at lines 7 & 8. Then adjust the details in the soap body as you wish for the Incident details (as you can see, I've made this a minimal example).  Other than that, paste everything below to your Powershell prompt, and you should hopefully have an Incident number returned when done:

     

    $url = 'http://midtierhostname:8080/arsys/services/ARService?server=arserverhostname&webService=HPD_IncidentServiceInterface'

    $headers = @{ "SOAPAction" = "urn:HPD_IncidentServiceInterface/Create_Incident"}

    $soap = [xml]@'

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:HPD_IncidentServiceInterface">

       <soapenv:Header>

          <urn:AuthenticationInfo>

             <urn:userName>Allen</urn:userName>

             <urn:password>password</urn:password>

          </urn:AuthenticationInfo>

       </soapenv:Header>

       <soapenv:Body>

          <urn:Create_Incident>

             <urn:Action>CREATE_INCIDENT</urn:Action>

             <urn:Summary>This is a test</urn:Summary>

             <urn:Incident_Type>Infrastructure Event</urn:Incident_Type>

             <urn:Reported_Source>Other</urn:Reported_Source>

             <urn:Impact>1-Extensive/Widespread</urn:Impact>

             <urn:Urgency>4-Low</urn:Urgency>

             <urn:Status>OPEN</urn:Status>

          </urn:Create_Incident>

       </soapenv:Body>

    </soapenv:Envelope>

    '@

    [xml]$ret = Invoke-WebRequest $url -Method post -ContentType 'text/xml' -Body $soap -Headers $headers

    $ret.GetElementsByTagName("ns0:Incident_Number").'#text'

     

     

    Here's an example of success after the last line:

     

    PS C:\users\ckelley> $ret.GetElementsByTagName("ns0:Incident_Number").'#text'

    INC000000239316

     

    This document was generated from the following discussion: An example of creating an incident via Web Services using Powershell