My customer wants to use SCSM 2010 for handling User Access Requests. These are implemented as Change Requests in SCSM 2010. I modified the Change Area List to have a Security item and created a Access Control child item below it. I then created a template to set the Change Area on User Access Change Requests to use the new Access Control change area. After adding in all of the required steps as Manual Activities the customer wanted to know if these could be automatically closed once they are completed. Time for a custom workflow using the Authoring Tool!
I actually got the idea for this from Marcel Zehner’s blog post on Auto-closing Incidents. I figured if it works for Incidents why can’t it work for Change Requests as well. Marcel’s post is located here.
In the Authoring Tool this type of workflow is very easy to create. Create a new Management Pack and then create a workflow in it. This particular Workflow will run on a schedule at some scheduled time(s) to go through the list of Completed change requests looking for any that are in the Access Control change area. Sounds like we need a script to run for this!
Since I am not a PowerShell guru, I asked for some help on the criteria portion of the script. Setting up a filter for a single criteria is easy, but that would have auto-closed all of the Completed change requests, not good! We only want to close the Completed User Access change requests so we need to filter on two criteria, Change Area = “Access Control” AND Status = “Completed”. Thanks go out to Patrik Sundquist who provided an answer to that!
After I got the script to work as desired I opened the Authoring Tool and placed a Windows PowerShell script as the only item in the workflow. We really don’t need anything else as the script handles all of the logic for filtering and closing the change requests. I saved the solution and imported the Management Pack.
I already had several User Access requests in my Test environment in various stages of completion so I triggered the workflow to run. It closed only the Completed User Access requests, just what we wanted. I checked the status of the workflow in Administration | Workflows | Status and saw that it was successful. I could then import the Management Pack into my Production environment for production use.
Let me take a moment and stress the importance of having a test environment that you can use for just such testing. If I had run the original script in a production environment, all of the Completed change requests would have bee immediately closed, which may not have been desired.
So here is the script. We’ll break it down and explain what each piece is doing as we go.
We’ll be using the SMLets module so we need to import that first.
We’ll establish the class of workitem we want to work with (Change Request)
$class = Get-SCSMClass -name System.WorkItem.ChangeRequest$
We’re going to set up the criteria we want to filter for, namely Completed User Access Requests
$statusCompletedId = (Get-SCSMEnumeration ChangeStatusEnum.Completed$).Id
$catAccessControlId = (Get-SCSMEnumeration ChangeAreaEnum.Security.AccessControl$).Id
$critString = "Status = '$statusCompletedId' and Area = '$catAccessControlId'"
$criteriaType = "Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectCriteria"
$criteria = New-Object $criteriaType $critString, $class
Here is where the change requests fitting the criteria are actually selected
Now that we have all of the changes that we need to modify this next statement actually sets the status on all selected objects to Closed
$changes = Get-SCSMObject -Criteria $criteria
$Changes | Set-SCSMObject -property Status -Value Closed
This workflow is a scheduled workflow that we have established needs to run several times during the day. Based on your own requirements you may need to vary this due to your own unique environmental conditions. The workflow itself only runs for a few seconds right now but as the number of objects that it needs to filter increases this time may also increase.
This small custom workflow may not seem like much but it will save the customer uncounted hours in manually closing all of these change requests. As the number of User Access requests increases over time that time savings will mount up.
As always, your comments are welcome! Please feel free to make any adjustments or changes to suit your environment.
NOTE: This solution may not be suitable for your environment. Please test all changes in a test environment prior to production implementation. While I have tested this code personally and it works for me, all code included here is used at your own risk, I cannot assume responsibility if anything goes wrong.