Definitive Service Manager Powershell
You’re syncing data from Operations Manager or Configuration Manager. Maybe even non-Microsoft products through the Cireson Asset Import Connector via a CSV or SQL database, maybe just uploading directly from Asset Excel. But what about the most custom of items in your environment? What about creating Work Items or Configuration Items from scratch? What about automating and streamlining your internal organization processes to lower the friction between IT and the rest of your organization?
What is arguably the most exciting part of Service Manager is that when it comes to Powershell you are only limited by your imagination when it comes to automating your ITSM and ITAM processes. But where do you begin? There are the out of box PowerShell cmdlets for Service Manager as well as the popular open source SMLets module. Which one should you use?
- Stock SCSM PowerShell Module: It’s 100% in box every time you install the SCSM console. The module behaves incredibly similar to the Operations Manager cmdlets. So if you’re coming from the land of SCOM it’s a rather easy onramp. Not only that, it comes with full support from Microsoft so it’s covered under any support cases you may raise.
- SMLets open source Module: Most examples you’ll find around the internet are using commands from this module. To say the least, it has quite the community hold on how to administer and control Service Manager. Unlike the stock module, you’ll need to retrieve this from the PowerShell Gallery. Which is as simple as typing
Install-Module "SMLets"
on the PowerShell command line. Like anything from the PowerShell Gallery – it comes from fellow passionate PowerShell users wanting to share their work and help make you, their fellow administrators’ lives easier. While you may not have formal support, you generally have the opportunity to contribute and get involved via GitHub; a route Microsoft has taken in recent years as more of their software becomes open source.
At the end of the day, your decision should be based around picking the right tool for the task at hand. Since those tasks are arguably endless in nature and vary in complexity. I’ll be highlighting a few relevant examples in upcoming posts. Through those examples I hope to show you not just how to construct your own processes, but help you form your own decision-making around why to use one over the other. We need to start somewhere, so regardless of the module you choose, here are 8 commands that when leveraged together can help you solve almost all of your organizational needs.
The Eight Commands
The true power of using the full System Center stack is it means all data flows back to Service Manager. Which is another way of saying – master these commands to understand anything you want about your environment.
SMLets: Get-SCSMClass
SCSM: Get-SCSMClass
It is a cornerstone of a command as it will be involved in most of the PowerShell you’ll write for SCSM. This command lets you identify a specific type of Class you want to work with in Service Manager. Incidents, Problems, Service Requests, Change Requests, Activities, Assets, and any other Configuration Item class.
SMLets: Get-SCSMObject
SCSM: Get-SCSMClassInstance
If Get-SCSMClass defines the type of thing (Class) you want to work with, then this command allows us to retrieve a specific item from it. For example,
- Incident is a Class, but IR5442 is an object/instance of that class
- Windows Computer is a Class, but scsmmgmt07 is a specific server (object/instance) in your environment
- Active Directory user is a Class, but Sheila is a member of that class within your organization
- Software Update is a Class, but KB4558753 is an actual update that you deploy
SMLets: Set-SCSMObject
SCSM: Update-SCSMClassInstance
Once you have retrieved a specific item to work with you can modify it as you so see fit. If you think about it, you’re already doing this every day in Service Manager. Whether you’re changing the Description on a Problem, moving an Incident’s Status to Resolved, Approving a Review Activity, or retiring a Hardware Asset. These are all operations you perform that set one or more properties on an item in Service Manager. Once you’ve retrieved an item from SCSM, you can immediately start working with properties on a specific item in your environment.
SMLets: New-SCSMObject
SCSM: New-SCSMClassInstance
Much like the name implies, this is how we can create wholly new items within Service Manager. Incidents, Change Requests, Problems, Service Requests, Hardware Assets, Subnets, Locations, Consumables, custom Configuration Items, or Users. The list goes on! Most Classes in your environment you can create objects/instances of. Which means all you need to do is pair this command with Get-SCSMClass to create.
SMLets: Get-SCSMRelationshipClass
SCSM: Get-SCSMRelationship
Think of it like the twin to Get-SCSMClass, it shares some similarities but has its own personality. This command lets you work with relationships in Service Manager. For example, the concept of an Affected User to a Work Item, the Custodian of a Computer, or the Impacted Service on an Incident. We’re still retrieving a Class of sorts – but again, the key difference here is we’re working with two Classes that relate to one another in a single command.
SMLets: New-SCSMRelationshipObject
SCSM: New-SCSMRelationshipInstance
Service Manager is a system whose entire focus is around that of maintaining relationships between objects. Who is the Affected User of the Service Request? Who is the Primary Owner of an Incident? What is the Impacted Service on a Problem? What are the Hardware Assets as they pertain to a Catalog Item? With this command you can define those relationships between two pre-existing items in Service Manager.
SMLets: Get-SCSMRelationshipObject
SCSM: Get-SCSMRelationshipInstance
The first time you retrieve an Incident with Get-SCSMClass and Get-SCSMObject/Get-SCSMClassInstance, you might be surprised to see that the “Affected User” field is nowhere in sight. But it’s with good reason it and a few others are missing. Such as the Created by User, the Assigned User, the Impacted Config Item, or the File Attachments, etc. Why? Because just like an Incident, they are all items that technically – can exist on their own. You don’t need an Incident to have a User. You don’t need a Service Request to have a Hardware Asset. These are all independent objects, of their own unique class, that simply relate to one another. It’s through these relationships you can reveal deeply insightful reporting within your own environment. Such as how many Service Requests does Marketing submit? How long on average does it take to Resolve an Incident from Accounting? How often are Change Requests submitted about Hardware Assets?
SMLets: Get-SCSMEnumeration & Get-SCSMChildEnumeration
SCSM: *See Note
It’s possible you’ll want to mass shift Incidents to a different Urgency or Support Group. Maybe you want to mark a bunch of Software Assets as Approved. What’s true in either of these scenarios is the values in questions are not free text like an Incident’s Title or a Hardware Asset’s Description. These values come from a List (or enumeration) that is centrally maintained in the “Library -> Lists” seen within the SCSM console. It’s worth calling out here that there is no stock SCSM command equivalent to this. *Note: It’s not to say it’s impossible to work with Lists via the stock commands, but it will require more effort than what’s available in SMlets. In fact, Matthew Dowst of Catapault Systems lays out how to achieve it.
More to Come
It’s worth clarifying that of course there are more than just these 8 commands. But I believe they are the 8 commands that have the highest frequency of use for most of things you’d want to do with Service Manager. What’s more, these 8 commands for the most part are all that stand between you and the digital goldmine of data sitting inside of Service Manager. So put your miner caps on because it’s time to extract data and connect to the ultimate PowerShell data source!
Check out Definitive Service Manager PowerShell: Part 2 now!
Got questions? Our community has answers.