PowerShell Tutorials


Login to Cherwell

Before we begin, a few points to note about this example:

  • Usernames and Passwords provided are for a demo/starter database, you will need to provide credentials for a user within your environment.

  • The web service URL provided is typical for a local install of Cherwell.

  • The result of this method will return “True” if successful.

# Define URL, and create proxy for web service
$URI = "http://localhost/CherwellService/?WSDL"
$cherwellService = New-WebServiceProxy -Uri $URI

# Create container for storing session cookie
$cherwellService.CookieContainer = New-Object system.net.CookieContainer

# Run ‘Login’ method with provided credentials
$cherwellService.Login(“henri”, “password”)


Back to Top


Create a Record

Before we begin, a few points to note about this example:

  • Creating records through the Web Service reads data in the same way as through the Browser Portal; therefore validation, calculations and required fields should all be considered.
  • The XML provided would create a record within a demo/starter instance. Your environment may have additional required fields, or content that invalidates some of the data.
  • This example follows on from Login, meaning you will need to run the Login method and store a session cookie in order to run this method.
  • The result of this method will return the RecID of the new record if successful.

To find out more about the XML structure used in the example below, read SDK Architecture.

$incidentID = $cherwellService.CreateBusinessObject("Incident","EventHenri BryceDesktop ManagementComputerRequest New Computer3From SOAP")


Back to Top


Find a Record

Before we begin, a few points to note about this example:

  • We have provided two options below, the first searches Cherwell using a named stored query, the second searches Cherwell using a given field name and value.
  • Both methods return an XML string as a list of records. Should you need to interrogate this list, you will need to map and deserialise the XML into a new class.

Query By Stored Query

$queryXml = $cherwellService.QueryByStoredQuery("Incident", "All Incidents")

Query By Field Value

$queryXml = $cherwellService.QueryByFieldValue("Incident", "Customer Display Name", "Henri Bryce")


Back to Top