Querying ITSM Incident tickets from Powershell

by Grzegorz Kulikowski

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:

[sourcecode language=”powershell”]
$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
(…)
[/sourcecode]

I have listed only few from the properties.

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

[sourcecode language=”powershell”]
$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)
[/sourcecode]

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://grzegorzkulikowski.info/2015/01/22/helpdesk_querylist_service-with-3-arguments-there-is-an-error-in-xml-document-3-4/

You may also like

5 comments

Enrique Martinez December 2, 2013 - 12:18 pm

Hi Grzegorz. Using your code to connect to ITSM via Powershell I’m not getting any results (the $answer variable remains empty), but using fiddler I’m able to see that both the call and the response from the web service are OK. Do you have any idea why the method isn’t returning any value in powershell? some blogs suggest that it may be something related to namespaces… Also, I’m calling the WS using ssl (https)

Reply
Querying itsm change requests from powerhsell | VMware and Powershell January 21, 2014 - 12:57 pm

[…] addition ton querying-itsm-incident-tickets-from-powershell […]

Reply
Creating an INC/Incident ticket in BMC ITSM using powershell | VMware and Powershell January 28, 2014 - 9:11 pm

[…] that from previous posts you already know how to consume this webservice from powershell (post1,post2) Let’s start our session […]

Reply
Maha June 17, 2014 - 3:39 pm

Works using SOAPUI. Your posting gave me the lead. thanks. If anyone looking for the SOAP params in XML

user.name
password

?

?

?

‘Incident Number’ = “INC000000378790” OR
‘Status’ = “In Progress”
?
100

Reply
Nitin September 2, 2016 - 1:10 pm

Hi,

I am working on the same but i am not able to do so. I have tried java code and then got your powershell script. But i am afraid its not working for me.

Reply

Leave a Reply

Chinese (Simplified)EnglishFrenchGermanHindiPolishSpanish