General: How to leverage PowerShell for task automation in Provance ITSM
Want to understand how to integrate and automate Provance ITSM with your current IT environment? This post will shed some light on this topic, describing some use-case scenarios, the modules available and what this allows you to do with Provance ITSM. At the end of this blog post, you'll have an overview of possible uses as well as some ideas of how to implement automations using PowerShell.
Provance ITSM sits on top of one of the most data-exchange-friendly platforms: Microsoft Dynamics® 365. It’s incredibly simple to import and export via the integrated data exchange tools over multiple scenarios. And running Dynamics 365 online allows even more interaction with Microsoft Cloud tools like Flow and PowerApps (and many more to come). But, if we look at the world outside of Microsoft, there are some challenges that Provance ITSM users might be facing, including interacting with data-providers during operations, leveraging existing monitoring tools, and reading data outside of Provance ITSM to create or update the ticket details.
The Provance ITSM Powershell module deals with these challenges in many different ways.
Integration Use Case Scenarios
- Integration of third-party monitoring tools: You’d like to have your non-Microsoft IT monitoring solution to create tickets in your ITSM solution to enable your team to react to performance issues and errors. You can create Incidents, Service Requests, Change Requests or Problems directly from the command-line. A command-line interface is supported by most monitoring solutions, so using PowerShell makes sense in this case.
- Transfer of ITSM Data to other systems: Sometimes it’s necessary to transfer data from an ITSM system to other systems for chargeback, reporting or other extended data processing. The PowerShell module allows you to read data from ITSM entities and use them as any other PowerShell object for further processing to target systems.
- Automation with third-party tools and "non-natively" supported apps: IT process automation can be a massive timesaver and can happen in multiple ways. Dynamics 365 allows flexible automation inside the platform with workflows, but sometimes it is necessary to use external automation platforms like Orchestrator or Azure Automation to reach out to other systems and automate things like user provisioning, software installation or changing group memberships. As many of these tasks happen in Microsoft systems, PowerShell is the choice to reach out to these external environments and manipulate data there.
With these use-cases in mind, let’s see what possibilities are available.
When you install Dynamics 365 for on premise, it is called Dynamics 2016. It ships with a PowerShell "Snapin". A Snapin is an extension to Powershell for a specific purpose (mostly used for applications) and it adds additional commands to PowerShell, for example, to control a Dynamics 365 instance. Even if the install is local, you can also connect to an online instance of Dynamics 365. For this Snapin, here is a link to all the necessary information: https://technet.microsoft.com/en-us/library/dn531202.aspx
The Snapin is mostly about administering Dynamics CRM and less about data exchange. Below, find a list of commands added with this Snapin (split between verb and noun). As an example, the first command would be "Add-CrmActivityToCrmRecord"
As you can see, the commands are mostly about administrating the CRM environment with some examples of data creation (Add-CrmNoteToCrmRecord). This is a nice start and shows the capabilities, but doesn’t help with the use-cases I described above.
So next, let’s look what the community has to offer.
The Microsoft.Xrm.Data.Powershell Module
For people who want to get deeper into data manipulation of CRM with PowerShell, the Snapin will not be sufficient. Luckily, two Microsoft Consultants, Sean McNellis and Kenichiro Nakamura, wrote a PowerShell module, which contains much deeper data manipulating functionality. The module is called Microsoft.Xrm.Data.Powershell and it’s hosted on Microsoft GitHub, a code and versioning platform. You can find the module here: https://github.com/seanmcne/Microsoft.Xrm.Data.PowerShell
To get a better understanding of the usage of this module, there is also a module with examples here: https://github.com/seanmcne/Microsoft.Xrm.Data.PowerShell.Samples
The module is a script-module, so you can look into the code and learn how the module receives and changes data in CRM. Version 2.5 of the module offers 92 commands and allows nearly any possible data modification (get, set, remove) inside Dynamics 365. The flexibility, however, brings some challenges because exchanging data forces you to know the exact entity names, relationships and other data structure relevant information, which needs to be explored before scripting your use-case. If you have understood all of this, then it is possible to work with CRM from the command-line for up to only 90% of your needs.
To get an idea of the rich set of commands, below is a list of all "Set” commands, which allow you to change data in CRM.
Just with the Set-CRMRecord, the logical entity instance can be changed.
As the module uses the SDK, all CRM-internal business logic applies. However, this uncovers the disadvantage of "Microsoft.Xrm.Data.PowerShell", especially with Provance ITSM as an application. When you create, for example, an Incident, the Provance logic forces you to add several properties and relationships to that Incident during creation, otherwise the command "New-CrmRecord" will fail. To get around this, we created the ProvanceITSM Module.
The ProvanceITSM Module
The ProvanceITSM module is a wrapper around the Microsoft.Xrm.data.PowerShell module and provides the business logic, entity names and relationships needed to get, set and create ProvanceITSM entities pre-packaged. This makes it a lot easier for administrators to create records and read data, as the output is packed into a commonly readable PSObject. Currently (Version 0.7), the module offers 15 commands, some of them are helper functions, so the core commandset for daily operations is shown below.
Show-Command shows us the mandatory parameters (those with a *) for New-ProvITSMIncident.
Following those rules, the command with mandatory parameters to create a new Incident would be:
New-ProvITSMIncident -Title 'Blogtest' -Contact 'Roman Stadlmair' -Description 'Sample Inc from PowerShell'
The result is:
The logic inside the ProvanceITSM Module does all the work for you in finding Contacts, Accounts, Services, and so on. Therefore, validation and business logic have already been taken care of, and you don’t need to consider this in calling commands from the module. Finally below is an example to retrieve data from ITSM with :
Get-ProvITSMINcident -Name '*INC/1092**' |Select-Object ID,Service,SlaStatusColor,StageName,Account|Format-Table -AutoSize
This will result in a list of incidents with some properties in a table.
Both the "Microsoft.Xrm.Data.PowerShell" and "ProvanceITSM" Modules are on the available on the PowerShell Gallery, a hosted Module platform by Microsoft. Having Powershell version 5.0 or above allows you to install the modules with a simple
This will bring both modules to your system.