Querying ITSM Incident tickets from Powershell

I have spent few days now in order to get information about tickets that are stored in ITSM. In order to query for INCident ticket in BMC ITSM we need
the uri to the webservice. How to get it ?
Access your internal ITSM server to get list of webservices:
http://itsm.midtier.lan/arsys/WSDL/protected/list

You will be prompted for user and password. Authenticate. After this you will receive a list of Web service name, service type, description. Copy link to
HPD_IncidentInterface_WS . This one will allow us to query our incident tickets.
Should be something like this:
http://itsm.midtier.lan/arsys/WSDL/protected/servername/HPD_IncidentInterface_WS
In order to consume it i use this uri:
http://itsm.midtier.lan/arsys/WSDL/public/servername/HPD_IncidentInterface_WS
Replace the ‘protected’ with ‘public’

Open powershell console and do the following:
$uri=’http://itsm.midtier.lan/arsys/WSDL/public/itsm.midtier.lan/HPD_IncidentInterface_WS
$myitsm=New-WebServiceProxy -Uri $uri -Namespace ITSM
Let’s complete authentication:

$auth= New-Object ITSM.AuthenticationInfo
$cred=get-credential
$auth.username=$cred.username
$auth.password= [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($cred.password))

You can always put it in plain text ($auth.username=’myuser’ // $auth.password=’yourpassword’)
$myitsm.AuthenticationInfoValue=$auth
Let’s set a INC number that we will be looking for

$tid=’INC000000000839′
Let’s build the search criteria

$criteria=”‘Incident Number’ = “”$tid”””

If you would like to build criteria based on your name and surname then it would look like this:
$criteria=”‘First Name’ = “”Grzegorz”” AND ‘Last Name’ = “”Kulikowski”” ”

Ok, lets perform our search. In my case i know that i will only receive 1 INC ticket.
$answer=$myitsm.HelpDesk_QueryList_Service($criteria,0,100)
$answer.count -> that will be 1 now as i have only 1 INC in my queue
the method: HelpDesk_QueryList_Service asks for ( search criteria, starting record number, maximum records returned)
i can now open my INC ticket to see what is inside, sample output:

$answer[0]
(...)
Assigned_Group                 : Greg Team
Assigned_Support_Organization  : Greg Team Org
Assignee                       : Grzegorz Kulikowski
City                           : Monki
Closure_Product_Category_Tier1 : Application
Company                        : Greg S.A
Country                        : Polska
Department                     : IT section
Summary                        : test123
Notes                          : test123
First_Name                     : Grzegorz
Impact                         : {Item4MinorLocalized}
Incident_Number                : INC000000049839
Internet_Email                 : gregua@internety.com
Last_Name                      : Kulikowski
Product_Categorization_Tier_1  : Application
Product_Categorization_Tier_2  : Infrastructure Services
Reported_Source                : {DirectInput}
Service_Type                   : {UserServiceRestoration}
Status                         : {InProgress}
Urgency                        : {Item4Low}
HPD_CI                         : Server
(...)

I have listed only few from the properties.

So actually, to run your query this portion of code is enough:

$myitsm=New-WebServiceProxy -Uri http://itsm.midtier.lan/arsys/WSDL/public/itsm.midtier.lan/HPD_IncidentInterface_WS -Namespace ITSM
$auth= New-Object ITSM.AuthenticationInfo
$cred=get-credential
$auth.username=$cred.username
$auth.password= [System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($cred.password))
$myitsm.AuthenticationInfoValue=$auth
$tid='INC000000000839'
$criteria="'Incident Number' = ""$tid"""
$answer=$myitsm.HelpDesk_QueryList_Service($criteria,0,100)

It does not look scary 😉 Took me some time to figure this out though. In next post i will try to show how to query for Changes and how to update tickets,crqs. Have in mind that i am not ITSM specialist, just end-user of this application. If you have any documents about using itsm web services, please share it in comments.

Useful links:
BMC Remedy IT Service Management 7.0 Integration
Using BMC ITSM OOB Web Service

In case of having issues check this post as well:

https://psvmware.wordpress.com/2015/01/22/helpdesk_querylist_service-with-3-arguments-there-is-an-error-in-xml-document-3-4/