Tag Archives: SMlets

SCSM: Update child incidents with parent ID in the title using PowerShell

Here is a small post i wanted to share.

A customer wanted a easy way to see if a incident is related to a parent incident without having to go into the case. They are using the Cireson Portal and the portal does not show if an Incident is a child unless you go into the Incident (See picture below).

So in order to make a quick fix that does not require Cireson to make changes to the portal i created a PowerShell script that will look for active parent incidents and go into each child and update the title so it says <title> (Child object of IR213) for example (See picture below).

The script is pretty simple done and it might generate performance loss if you schedule it on a fast interval. But that’s up to you to decide what interval the script should run at.

The script


Close ALL work items in SCSM with PowerShell

I was at a customer that had several 1000 work items, Incident, Service Requests, Change, Activities etc. I wanted to close all items and make the test environment clean. So i created a PowerShell script based on SMlets that will take all work items and close them.

Be careful so you don’t run this script on a production environment :)


Service Manager 2012 PowerShell Exchange “Connector”

There is a Exchange connector for Service Manager but in my experience i think it lacks a bit of features. And it is not possible to configure it as much as i want to. To create a work around for the exchange connector i created a Powershell based “connector”

This is a kind of concept that shows you that you can create awesome stuff with Powershell and tweak you’re mail integration a lot more then with the normal connector.

The “connector” works this way, you schedule it on a management server for a interval of 5 minutes and it will use the exchange web service to look in a mailbox for emails. The script also depends on SMlets. You can download The Exchange web service here and SMlets here

By default it process all emails that has a IR prefix or SR prefix. If it finds a email that does not contain a valid prefix it is processed as trash and an email is sent to the mail sender that it contained a invalid case number.

You can change this behavior to allow all mail that does not contain a prefix or SR/IR so the “connector” will create a new incident with that content. The new incident will use a specified Incident template.

I have tested the script from a Windows 2012 R2 server with Service Manager 2012 R2 (works with UR4 also) and on a office 365 mailbox. It should work against Exchange 2010 for example if auto discovery is configured.

Functions in version 1.0

  • Incident Comments from email
  • Service Requests comments from email
  • Incident attached files added to the Incident
  • Service Request attached files added to the service request
  • Ability to create new incidents from email based on incident templates
  • If the sender of the email does not exists as a CI in service manager database an internal account will be created for that user.
  • All processed emails are kept in a folder in the mailbox
  • If the incident or service request is in the status closed the user gets an email saying the mail was not processed due to cases being closed.

Here is an example for a email that contains attached file. The subject for this email was IR122 and contained the file IR122.txt and the text “This is a test comment sent into IR122 with an attached file”


After the powershell script has run we can look in the action log and you can now see that there is an entry from me and a attached file (Bifogad fil in Swedish)


And on the related object page we can see the attached file.email_after_incident_process_relatedItems

Functions that i am working on in version 1.1

  • Be able to resolve incident by sending [resolved] in the email tag
  • Be able to complete service requests by sending [completed] in the email tag
  • Splitting the code into more functions and modules to get an more easy overview of the code


The script is available on technet gallery. Here is the link.

If you want something more added in future versions just throw in a comment below.


Service Manager PowerShell examples

I have almost used service manager for 1,5 year now and over the time i have created a bunch of PowerShell scripts to do lots of different things. But i have noticed that sometime it was really hard to find some examples to the code. So here is a list of some code examples that i hope will help you.

Not all examples are completed so you need to fill in some information but the basic of how you can do it are there. Got any question just add a comment and i will answer as soon as i can.

Almost all script examples requires you to install SMlets you can find it on codeplex or here

Add an analyst comment to a Incident

This example is for adding a comment to a incident. You can use the smlets set-scsmincident -id 333 -comment “Hello” if you want but in this case we get more flexible and can set if it’s private and so on.

Add an end-user comment to incident

In this case we can use this example or look at the example below “Add an analyst comment to an incident” and modify it so the AnalystComment is set to EndUserComment instead. More like “Add an end-user comment to service request”

Add an end-user comment to Service Request

This example shows you how you can add a end-user comment to a service request. You need the $SCSMObject from a get-scsmobject.

Apply a template to an incident

This examples lets you set a template on a incident. You need to get your template ID by issue get-scsmobjecttemplate. Se example below.

Now get the Name of your template and add it to the template variable below.

Upload an attachment to a service request

This is not my own script. A college of mine wrote it. Thanks Evert. But it allows you to add attachements to a service request. All files in the $directory will be added to a id in $SCSMID

Set affected service when creating an incident

This example allows you to set a affected service on your incident. In this example not all variables are visible but you can replace the $variables with your own on the propertyHashtable. In this example we are setting the business service Gnu as affected service.

Populate AD-user class with email-address from active directory

In this example i am populating the email to the note field. Best practice would be to extend the Microsoft.AD.User class and add a field called email or something.