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 = "'ASGRP' = ""$TeamName"" AND 'Change Request Status' != ""Cancelled"" AND 'Change Request Status' != ""Closed"" AND 'Change Request Status' != ""Completed"" AND 'Change Request Status' != ""Rejected"" "
$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 |% {"$($_.Name) has $($_.Count) change requests assigned."}

#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/

Advertisements

6 thoughts on “Querying itsm change requests from powershell

  1. Cannot convert argument “Impact”, with value: “Item4MinorLocalized”, for “HelpDesk_Submit_Service” to type
    “System.Nullable`1[ITSM.ImpactType]”: “Cannot convert value “Item4MinorLocalized” to type “ITSM.ImpactType”. Error:
    “Invalid cast from ‘ITSM.ImpactType’ to ‘ITSM.ImpactType’.””

  2. Hi John, first of all, i was not describing yet how to create a INC ticket, will do that soon though. In your case are you using [ITSM.ImpactType]’Item4MinorLocalized’ as the argument ? or just ‘Item4MinorLocalized’ ?

  3. Pingback: Creating an INC/Incident ticket in BMC ITSM using powershell | VMware and Powershell
  4. Hi there,
    Can you help me with how to query the Change_Query_Service method? I can’t seem to work out how to supply the CRQ number into this and have it search. Error I always get is like this:

    “Cannot find an overload for “Change_Query_Service” and the argument count:”

    Thanks for the awesome post. Very Helpful.

    • Are you passing any arguments to that method ? I can’t remember from top of my head, but i think you need to pass the criteria to it. Can’t you try to use the method i have described here?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s