• Glen (Xapity)

PowerShell for SCSM: Working with History Tab Information


A question came up in the forums about assigning an Service Request (SR) to the user that had put the SR On Hold. The solution that I thought of involved getting the history on the SR and finding the username of the analyst that put the SR On Hold.


This blog outlines some general examples of PowerShell code that will help when dealing with History tab information and includes the full script example of assigning the SR to the analyst that put the SR On Hold.

Define Classes and Relationships

First define any relationships and Classes that you might need. I am using the example from the forum post, so will use Service Request. You should be able to modify the examples below for other work items.

Import-Module SMLets -Force

$WorkItemID = "SR132"

$WorkItemClass = Get-SCSMClass System.WorkItem.ServiceRequest$

$WorkItemObject = Get-SCSMObject -Class $WorkItemClass -Filter "Id -eq $WorkItemID "

Get the History Information

Now we can get the History tab information from the SR object:

$History = Get-SCSMObjectHistory -Object $WorkItemObject

This will give us the following:


You can see that each update has a time stamp and User. Each update contains a list of the values that have been made or updated.

Properties on History

If we look at the Properties on $History we can see that we are probably interested in the $History.History property.

$History | Get-Member


Changes on the History Tab

We can now loop thorough the changes that were made looking at the $History.History property.

foreach ($Change in $History.History ) { Write-Host $Change |FL }


Not as useful as you would expect.

Properties on each Change on the History Tab

So let's look at the properties on each Change in the above loop.

$Change | Get-Member

And we are most interested in the contents of the $Change.Changes list property.


Loop to get each Value update

So we will loop through each update ($Change.Changes property) made in each of the History changes:

foreach ($Change in $History.History ) { foreach ($Update in $Change.Changes ) { { Write-host "Update entered by $($Change.Username) " $Update | FL } }

Now we can see what values have changed, both the old and new values, who made the change and what type of change it was. This is what we wanted!


From this point you can collect the data and use it as required.

Full Script

In the Forum example and the Full Script, I added in the Enums for SR In Progress and SR On Hold, added the User class and Assigned To relationship references.

By looping through the changes looking at the Old Value enum for In Progress and New Value enum for On Hold, I was then get the user that made the change and able to set the Assigned to user on the SR to the last analyst to put the SR on Hold.

Download Script: PlaceSRonHold.zip


Read more PowerShell for SCSM Blogs



Xapity PowerShell Activity

The Xapity PowerShell Activity is an Activity for Microsoft SCSM that enables PowerShell scripts to be run in SCSM activity workflows. Automate more of your processes directly in SCSM. Scripts are stored and updated from a central script repository. The scripts execution output can be viewed and if a failure occurs, an email notification can be sent.

See more Xapity Product videos

Xapity - Innovative Software for SCSM - Discover our Products

#PowerShellActivity #Tips #PowerShell #SCSM

© 2020 Xapity PTY LTD ABN: 81 611 883 482

  • White RSS Icon
  • White YouTube Icon
  • White Vimeo Icon
  • Facebook Clean
  • Twitter Clean