Creating an INC/Incident ticket in BMC ITSM using powershell

Hello,
this time we will create an ITSM INC ticket using the HPD_IncidentInterface_Create_WS web service.
I assume that from previous posts you already know how to consume this webservice from powershell (post1,post2)
Let’s start our session first:

$myitsm=New-WebServiceProxy -Uri http://itsm.midtier.lan/arsys/WSDL/public/itsm.midtier.lan/HPD_IncidentInterface_Create_WS -Namespace ITSM
$ITSMQueryUser='ourITSMlogin'
$auth= New-Object ITSM.AuthenticationInfo
$auth.username=$ITSMQueryUser
#you can also just simply use: $passwd='mysecretpasswordformyitsmuser'
$passwd= get-content C:\passwdforouruser.txt | convertto-securestring
$auth.password=[System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($passwd))
$myitsm.AuthenticationInfoValue=$auth

At this point we can start creating our incident ticket in ITSM using HelpDesk_Submit_Service method from $itsm web service object.
Let’s first read what is required to be sent, by the way, it is required to fill out all arguments. I saw a lot of posts on bmc communities that people had issues because they have missed some field. When building arguments for this method it might be little complicated, because of the number of them. In my case i had to fill out 60 arguments. It might be different for your environment i suppose. Lets inspect the method first:

$myitsm.HelpDesk_Submit_Service
string HelpDesk_Submit_Service(string[] Assigned_Group, string Assigned_Group_Shift_Name, string Assigned_Support_Company, string Assigned_Support_Organization, string Assignee, string
Categorization_Tier_1, string Categorization_Tier_2, string Categorization_Tier_3, string CI_Name, string Closure_Manufacturer, string Closure_Product_Category_Tier1, string
Closure_Product_Category_Tier2, string Closure_Product_Category_Tier3, string Closure_Product_Model_Version, string Closure_Product_Name, string Department, string First_Name,
System.Nullable[ITSM.ImpactType][] Impact, string Last_Name, string Lookup_Keyword, string Manufacturer, string Product_Categorization_Tier_1, string Product_Categorization_Tier_2, string
Product_Categorization_Tier_3, string Product_Model_Version, string Product_Name, System.Nullable[ITSM.Reported_SourceType] Reported_Source, string Resolution, string Resolution_Category_Tier_1,
string Resolution_Category_Tier_2, string Resolution_Category_Tier_3, System.Nullable[ITSM.Service_TypeType] Service_Type, ITSM.StatusType[] Status, string Action,
System.Nullable[ITSM.Create_RequestType] Create_Request, string Summary, string Notes, System.Nullable[ITSM.UrgencyType][] Urgency, string Work_Info_Summary, string Work_Info_Notes,
System.Nullable[ITSM.Work_Info_TypeType] Work_Info_Type, System.Nullable[datetime][] Work_Info_Date, System.Nullable[ITSM.Work_Info_SourceType] Work_Info_Source,
System.Nullable[ITSM.Create_RequestType] Work_Info_Locked, System.Nullable[ITSM.Work_Info_View_AccessType] Work_Info_View_Access, string[] Middle_Initial, System.Nullable[ITSM.Status_ReasonType]
Status_Reason, string Direct_Contact_First_Name, string Direct_Contact_Middle_Initial, string Direct_Contact_Last_Name, string TemplateID, string ServiceCI, string ServiceCI_ReconID, string HPD_CI,
string HPD_CI_ReconID, string HPD_CI_FormName, string WorkInfoAttachment1Name, byte[] WorkInfoAttachment1Data, int WorkInfoAttachment1OrigSize, bool WorkInfoAttachment1OrigSizeSpecified)

Now… it’s really hard to see anything in here… Let’s make it more human readable

$myitsm.HelpDesk_Submit_Service -split ','
string HelpDesk_Submit_Service(
 string[] Assigned_Group
 string Assigned_Group_Shift_Name
 string Assigned_Support_Company
 string Assigned_Support_Organization
 string Assignee
 string Categorization_Tier_1
 string Categorization_Tier_2
 string Categorization_Tier_3
 string CI_Name
 string Closure_Manufacturer
 string Closure_Product_Category_Tier1
 string Closure_Product_Category_Tier2
 string Closure_Product_Category_Tier3
 string Closure_Product_Model_Version
 string Closure_Product_Name
 string Department
 string First_Name
 System.Nullable[ITSM.ImpactType][] Impact
 string Last_Name
 string Lookup_Keyword
 string Manufacturer
 string Product_Categorization_Tier_1
 string Product_Categorization_Tier_2
 string Product_Categorization_Tier_3
 string Product_Model_Version
 string Product_Name
 System.Nullable[ITSM.Reported_SourceType] Reported_Source
 string Resolution
 string Resolution_Category_Tier_1
 string Resolution_Category_Tier_2
 string Resolution_Category_Tier_3
 System.Nullable[ITSM.Service_TypeType] Service_Type
 ITSM.StatusType[] Status
 string Action
 System.Nullable[ITSM.Create_RequestType] Create_Request
 string Summary
 string Notes
 System.Nullable[ITSM.UrgencyType][] Urgency
 string Work_Info_Summary
 string Work_Info_Notes
 System.Nullable[ITSM.Work_Info_TypeType] Work_Info_Type
 System.Nullable[datetime][] Work_Info_Date
 System.Nullable[ITSM.Work_Info_SourceType] Work_Info_Source
 System.Nullable[ITSM.Create_RequestType] Work_Info_Locked
 System.Nullable[ITSM.Work_Info_View_AccessType] Work_Info_View_Access
 string[] Middle_Initial
 System.Nullable[ITSM.Status_ReasonType] Status_Reason
 string Direct_Contact_First_Name
 string Direct_Contact_Middle_Initial
 string Direct_Contact_Last_Name
 string TemplateID
 string ServiceCI
 string ServiceCI_ReconID
 string HPD_CI
 string HPD_CI_ReconID
 string HPD_CI_FormName
 string WorkInfoAttachment1Name
 byte[] WorkInfoAttachment1Data
 int WorkInfoAttachment1OrigSize
 bool WorkInfoAttachment1OrigSizeSpecified)

Little bit better 😉 Few reminders here, when you will fill this out, make sure you stick to proper type as well. If it is required to type a string for property X we type ‘some value’. If it is required to give values for Reported_Source we need to make sure that we are giving the proper type of reported source like in this example :

[enum]::getvalues([ITSM.Reported_SourceType])
DirectInput
Email
ExternalEscalation
Fax
SelfService
SystemsManagement
Phone
VoiceMail
WalkIn
Web
Other
BMCImpactManagerEvent

So if we will be giving this argument we will be giving it as : methodX(arg1,arg2,[ITSM.Reported_SourceType]’Phone’,argN) for example.
Again i would recommend checking bmc communities in case of issues while doing this, i found there a lot of great tips and documents, links are mentioned in previous post. A must see is document written by Carl Wilson (Using BMC ITSM OOB Web Services.doc (check links section in previous posts). I had to type bit more in my case, but i guess everybody might have to fill out his arguments in a little different way.Anyway…
For me the best way for first time to fill out arguments was to create a spreadsheet document with 2 colums, in first i have the definition in second i type my values. It looks like this:
itsm powershell
We can fill it out now with less chance on making an error by putting value in wrong place. In my case i could not create an INC ticket without filling out the HPD_CI/HPD_CI_RecondID,ServiceCI,ServiceCI_RecondID. In order to fill this out you need to take a look at existing INC ticket, if you want to make a ticket like that just copy those values. In previous post i wrote how to query INC tickets so now we just need to take value from it.

Incident_Number        HPD_CI_ReconID
---------------        --------------
INC00000001            RE00XXXXXXXXXXXXXXXXXXXXXXXXXX
INC00000002            RE00XXXXXXXXXXXXXXXXXXXXXXXXXX
INC00000003            RE00YYYYYYYYYYYYYYYYYYYYYYYYYY

Now when copying those values for HPD_CI_ReconID for example, they are unique for a kind of INC ticket. So if you want to make a ticket that looks like existing ticket Z in your itsm, then just copy values from his properties. Those values are not the same for all kinds of tickets. I have created myself 5 identical tickets with different summaries/descriptions, they all had the same HPD_CI_ReconID. Same goes for ServiceCI/ServiceCI_ReconID. Please have in mind that i don’t have any administrative knowledge of itsm, i’m just end user. Please correct me in comments if i write something here which is not true. All of this was created by making hundreds of attempts via powershell/soap ui.

Also the easiest way just to create a look a like ticket is first to grab him and inspect via powershell so you know which values to put in the request method.
Below is the code for HelpDesk_Submit_Service that i have used for creating simple INC ticket. It has a variable inside $date, which is $date=get-date

$myitsm.HelpDesk_Submit_Service(
'MYTEAM',
$null,
'MYCOMPANY',
'MYORGANIZATION',
'Grzegorz Kulikowski',
$null,
$null,
$null,
$null,
$null,
'Application',
'Server Hardware',
'Production',
$null,
$null,
'Mega Services',
'Grzegorz',
[ITSM.ImpactType]'Item4MinorLocalized',
'Kulikowski',
$null,
$null,
'Application',
'Server Hardware',
'Production',
$null,
$null,
[ITSM.Reported_SourceType]'Other',
$null,
$null,
$null,
$null,
[ITSM.Service_TypeType]'UserServiceRestoration',
[ITSM.StatusType]'InProgress',
'CREATE',
[ITSM.Create_RequestType]'No',
'Description',
'Notes from test ticket',
[ITSM.UrgencyType]'Item4Low',
'Created from Psapp',
'Notes in notes',
[ITSM.Work_Info_TypeType]'General',
$date,
[ITSM.Work_Info_SourceType]'Other',
[ITSM.Create_RequestType]'No',
[ITSM.Work_Info_View_AccessType]'Internal',
'',
$null,
$null,
$null,
$null,
$null,
'Infrastructure Services',
'RE00YYYYYYYYYYYYYYYYYYYYYYYYYYYY',
'Server Hardware',
'RE00XXXXXXXXXXXXXXXXXXXXXXXXX',
$null,
$null,
$null,
$null,
$null)

If you will execute this method in return you will get a INCnumber of the ticket that you have created.
itsm3
In the response we get the INC ticket number. In this picture i just cut out the code as it would be too big ;).
itsm2

Some other things, when you create the ticket like i do here, you will notice that i am putting it to In progress state, as i can’t put it in new for myself as myself, it can be either in pending or in progress. That should not be the problem if you would not assign it to anybody or to somebody else than you. If you get stuck i recommend to write this in soap ui. Links that might be useful :
https://communities.bmc.com/thread/49687
https://communities.bmc.com/community/bmcdn/bmc_it_service_support/change_process_management/blog/2013/10/18/the-pulse-communicate-effectively-with-change-notifications

Below you can check the body of soap request that i have used to create an INC ticket.

<soapenv:Body>
      <urn:HelpDesk_Submit_Service>
         <!--1 or more repetitions:-->
         <urn:Assigned_Group>MYTEAM</urn:Assigned_Group>
         <urn:Assigned_Group_Shift_Name></urn:Assigned_Group_Shift_Name>
         <urn:Assigned_Support_Company>MYCOMPANY</urn:Assigned_Support_Company>
         <urn:Assigned_Support_Organization>MYORGANIZATION</urn:Assigned_Support_Organization>
         <urn:Assignee></urn:Assignee>
         <urn:Categorization_Tier_1></urn:Categorization_Tier_1>
         <urn:Categorization_Tier_2></urn:Categorization_Tier_2>
         <urn:Categorization_Tier_3></urn:Categorization_Tier_3>
         <urn:CI_Name>Server Hardware</urn:CI_Name>
         <urn:Closure_Manufacturer></urn:Closure_Manufacturer>
         <urn:Closure_Product_Category_Tier1></urn:Closure_Product_Category_Tier1>
         <urn:Closure_Product_Category_Tier2></urn:Closure_Product_Category_Tier2>
         <urn:Closure_Product_Category_Tier3></urn:Closure_Product_Category_Tier3>
         <urn:Closure_Product_Model_Version></urn:Closure_Product_Model_Version>
         <urn:Closure_Product_Name></urn:Closure_Product_Name>
         <urn:Department>MEGA Services</urn:Department>
         <urn:First_Name>Grzegorz</urn:First_Name>
         <!--1 or more repetitions:-->
         <urn:Impact>4-Minor/Localized</urn:Impact>
         <urn:Last_Name>Kulikowski</urn:Last_Name>
         <urn:Lookup_Keyword></urn:Lookup_Keyword>
         <urn:Manufacturer></urn:Manufacturer>
         <urn:Product_Categorization_Tier_1>Application</urn:Product_Categorization_Tier_1>
         <urn:Product_Categorization_Tier_2>Server Hardware</urn:Product_Categorization_Tier_2>
         <urn:Product_Categorization_Tier_3>Production</urn:Product_Categorization_Tier_3>
         <!--Optional:-->
         <urn:Product_Model_Version></urn:Product_Model_Version>
         <urn:Product_Name></urn:Product_Name>
         <urn:Reported_Source>Other</urn:Reported_Source>
         <urn:Resolution></urn:Resolution>
         <urn:Resolution_Category_Tier_1></urn:Resolution_Category_Tier_1>
         <urn:Resolution_Category_Tier_2></urn:Resolution_Category_Tier_2>
         <urn:Resolution_Category_Tier_3></urn:Resolution_Category_Tier_3>
         <urn:Service_Type>Infrastructure Restoration</urn:Service_Type>
         <!--1 or more repetitions:-->
         <urn:Status>New</urn:Status>
         <urn:Action>CREATE</urn:Action>
         <urn:Create_Request>NO</urn:Create_Request>
         <urn:Summary>Test Summary</urn:Summary>
         <urn:Notes>Test Notes</urn:Notes>
         <!--1 or more repetitions:-->
         <urn:Urgency>4-Low</urn:Urgency>
         <urn:Work_Info_Summary>SummaryWRKinfo</urn:Work_Info_Summary>
         <urn:Work_Info_Notes>NotesWRKinfo</urn:Work_Info_Notes>
         <urn:Work_Info_Type></urn:Work_Info_Type>
         <!--1 or more repetitions:-->
         <urn:Work_Info_Date>2014-01-28T12:30:00.000+01:00</urn:Work_Info_Date>
         <urn:Work_Info_Source>Other</urn:Work_Info_Source>
         <urn:Work_Info_Locked>No</urn:Work_Info_Locked>
         <urn:Work_Info_View_Access>Internal</urn:Work_Info_View_Access>
         <!--1 or more repetitions:-->
         <urn:Middle_Initial></urn:Middle_Initial>
         <urn:Status_Reason></urn:Status_Reason>
         <urn:Direct_Contact_First_Name></urn:Direct_Contact_First_Name>
         <urn:Direct_Contact_Middle_Initial></urn:Direct_Contact_Middle_Initial>
         <urn:Direct_Contact_Last_Name></urn:Direct_Contact_Last_Name>
         <urn:TemplateID></urn:TemplateID>
         <urn:ServiceCI>Infrastructure Services</urn:ServiceCI>
         <urn:ServiceCI_ReconID>---I have copied this value from existing ticket---</urn:ServiceCI_ReconID>
         <urn:HPD_CI>Server Hardware</urn:HPD_CI>
         <urn:HPD_CI_ReconID>---I have copied this value from existing ticket---</urn:HPD_CI_ReconID>
         <urn:HPD_CI_FormName></urn:HPD_CI_FormName>
         <!--Optional:-->
         <urn:WorkInfoAttachment1Name>?</urn:WorkInfoAttachment1Name>
         <!--Optional:-->
         <urn:WorkInfoAttachment1Data>?</urn:WorkInfoAttachment1Data>
         <!--Optional:-->
         <urn:WorkInfoAttachment1OrigSize>?</urn:WorkInfoAttachment1OrigSize>
      </urn:HelpDesk_Submit_Service>
   </soapenv:Body>

Don’t forget to fill out the authentication bit :

<urn:AuthenticationInfo>
<urn:userName>ITSMusername</urn:userName>
<urn:password>passwd</urn:password>

Ideally in response in SoapUI you should get something similar to this:

      <ns0:HelpDesk_Submit_ServiceResponse xmlns:ns0="urn:HPD_IncidentInterface_Create_WS">
         <ns0:Incident_Number>INC0000000111111</ns0:Incident_Number>
      </ns0:HelpDesk_Submit_ServiceResponse>

One more thing about the soap request. Make sure that you put the values in some fields as you see them in webform and not how powershell is returning them. An example here would be :
‘4-Low’
‘4-Minor/Localized’
We have to type it as ‘4-Low’ and not [ITSM.UrgencyType]—>’Item4Low’, or ‘4-Minor/Localized’ and not [ITSM.ImpactType]—>’Item4MinorLocalized’, like we typed when we were doing this via powershell.

I hope this post will help you to start creating incident tickets in ITSM from powershell using its webservices. If anything is unclear let me know, although like i have mentioned earlier i am no itsm specialist.

vBeers 5th February in Cracow, PL!

If you are planning to be in Cracow on 5th of February and expect to be thirsty 😉 Join us @ vBeer
Location: pub Omerta
Address: Krakow, Kazimierz, ul. Kupa 3, Poland
Date: 05.02.2014
Time: 20:00 (08:00 PM)
more details:
http://www.vbeers.org/2014/01/20/vbeers-krakow-poland-wed-5th-february-2014/
See you there!

Querying itsm change requests from powershell

id addition ton querying-itsm-incident-tickets-from-powershell post..

Let’s start this time from a link… it will save us A LOT ! of time later on. I found this document of bmc communities :
https://communities.bmc.com/docs/DOC-5686
BMC Remedy IT Service Management 7.0 Integrations.pdf
So i advise to go trough this document again even briefly, when you will be building criteria for queries it might save you some time. One more useful thing. When you will be doing those criteria for finding the right crqs use the field names as they are described in the first column in the document ‘DB field on interface form’. Now let’s do some searching.
FIND:
all changes that belong to team X and they are in status Y and Z
What if we don’t know the value of the possible status values ?

[enum]::GetValues([ITSMCRQ.Change_Request_StatusType])
Draft
RequestForAuthorization
RequestForChange
PlanningInProgress
ScheduledForReview
ScheduledForApproval
Scheduled
ImplementationInProgress
Pending
Rejected
Completed
Closed
Cancelled

Same goes for other attributes:
I have a list of ITSM change request in my $answer array variable. I have some change in $answer[3]
I want to know what was the reason for status. Let’s check it, in order to do that we need display its property called Status_Reason.
$answer[3].Status_Reason
Successful
Ok, it means that this change was closed as it was successful. What if we would like to build later on a criteria with status reason of something else like Successful but with some issues ? We would first need to know what are the value possibilities of this field so again:

[enum]::GetValues($answer[3].Status_Reason.gettype())
Successful
...
SuccessfulwithIssues
Unsuccessful
...
ScheduleConflicts
..
OnHold
AutomaticallyClosed

This time as a argument for GetValues method from Enum class i use directly the type that is used by status reason(using the gettype method on that property). You can read more about enum class on msdn and for example here -> latkin.org.
That said we should be able to construct our criteria as we want.. So how about making one that will:
1) Show only CRQs assigned to our team and active
2) CRQs should not be closed nor cancelled/ closed/ completed/ rejected
Using method Change_QueryList_Service we will get CRQs that match our search criteria. Remember to user proper filed names as per the document from the beggining of this post.
Similar to what i wrote in the post about incidents:

#in case you want to store password for the username you would first need to export it to file for example
#read-host -assecurestring | convertfrom-securestring | out-file C:\x\y\z\generatedpassword.txt
$itsmQueryUser='yourITSMusername'
$myitsmCRQ=New-WebServiceProxy -Uri http://itsm.midtier.lan/arsys/WSDL/public/itsm.midtier.lan/CHG_ChangeInterface_WS -Namespace ITSMCRQ
$authCRQ=New-Object ITSMCRQ.AuthenticationInfo
$authCRQ.username=$ITSMQueryUser
$passwd= get-content C:\x\y\z\generatedpassword.txt | convertto-securestring
$authCRQ.password=[System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($passwd))
$myitsmCRQ.AuthenticationInfoValue=$authCRQ
$criteriaCRQ = &quot;'ASGRP' = &quot;&quot;$TeamName&quot;&quot; AND 'Change Request Status' != &quot;&quot;Cancelled&quot;&quot; AND 'Change Request Status' != &quot;&quot;Closed&quot;&quot; AND 'Change Request Status' != &quot;&quot;Completed&quot;&quot; AND 'Change Request Status' != &quot;&quot;Rejected&quot;&quot; &quot;
$CRQTickets=$myitsmCRQ.Change_QueryList_Service($criteriaCRQ,0,100)
$CRQPeopleStats = $CRQTickets |Group-Object -Property Assignee |Where-Object {($_.Name)}| select Count, @{n='Name';e={$($_.Values)}}
$TotalCRQNumber=@($CRQTickets).count

#You can do then for example enumaration through people in those crqs like:

$CRQPeopleStats |% {&quot;$($_.Name) has $($_.Count) change requests assigned.&quot;}

#we should get something similar to this:

#John Kowalski has 4 change requests assigned.
#Robert Zimowski has 2 change requests assigned.
#Cathrine Powerszelska has 12 change requests assigned.
#Thomas Itsmowski has 6 change requests assigned.
#We could also generate a nice table:

$CRQTickets | Select Infrastructure_Change_ID, Summary, @{n='CreatedBY';e={$_.First_Name+' '+$_.Last_Name}}, @{n='CRQ Coordinator';e={$_.Change_Coordinator[0]}}

Infrastructure_Change_ID  Summary                      CreatedBY             CRQ Coordinator
CRQ000034215209           Wazny update do wykonania    Grzegorz Kulikowski   Grzegorz Kulikowski
CRQ000012159912           Paczowanie paczek            Grzegorz Powerszelski Grzegorz Kulikowski

I hope this post will make it easier to get started with querying itsm tickets either incident or change request tickets via powershell.

You can also have a look at that post if you are having issue with querying:

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