Showing posts with label SCSM. Show all posts
Showing posts with label SCSM. Show all posts

2016/03/10

PowerShell/SCSM - Get Review Activities Rejected in the last 60 days

In the following post I demonstrate how you can retrieve all the rejected Review Activities from the last 60 days. I also include the DisplayName, the Decision and the Comment of the Reviewer.

Hope this help some people out there.


# Smlets Module
Import-module -name smlets

# Capture the SR Failed Status
$RAStatusFailed = Get-SCSMEnumeration -Name ActivityStatusEnum.Failed$

# Capture the date from where we are searching
$RAModifiedDay = (get-date).Adddays(-60)

# Get the Manual Activity Class
$RAClass = Get-SCSMClass -Name System.WorkItem.Activity.ReviewActivity$

# Get the Criteria Class
$CriteriaClass = “Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectCriteria”

# Define the filter
$Filter = "Status = '$($RAStatusFailed.Id)' AND LastModified > '$RAModifiedDay'"

# Create the Criteria Object
$CriteriaObject = new-object $CriteriaClass $Filter,$RAClass

# Get the Reviewer relationship classes
$RAHasReviewerClass = Get-SCSMRelationshipClass System.ReviewActivityHasReviewer$
$ReviewerIsUserClass = Get-SCSMRelationshipClass System.ReviewerIsUser$

# Get the RA rejected in the last 60 days
Get-SCSMObject -criteria $CriteriaObject |
    ForEach-Object -Process {

        # Current Review Activity
        $RA = $_

        # Get the rejected review(s) on this RA
        $RejectedReview = Get-SCSMRelatedObject -SMObject $RA -Relationship $RAHasReviewerClass | Where {$_.decision.displayname -eq 'Rejected'}

        foreach ($item in $RejectedReview)
        {
            # Get the reviewer information
$ReviewerObj = Get-SCSMRelatedObject -SMObject $Item -Relationship $ReviewerIsUserClass
            
            # Create a new PowerShell Object
            [pscustomobject][ordered]@{
                ReviewActivityName = $RA.Name
                ReviewerDisplayName = $ReviewerObj.displayname
                Decision = $item.decision.displayname
                Comments = $item.comments -as [string]
            }
}
    }#| Format-List



2016/03/09

PowerShell/SCSM - Get Manual Activities Completed per Assigned user in the last month

I wanted to expend a bit on the previous post which retrieved all the Manual Activities completed in the last month.

I want to go a step further and get the top Users who closed the most Manual Activities in that period.


# Smlets Module
Import-module -name Smlets

# Get the Manual Activity Class
$MAClass = Get-SCSMClass -Name System.WorkItem.Activity.ManualActivity$

# Get the Manual Activity Completed Status Enumeration
$MAStatusCompleted = Get-SCSMEnumeration -Name ActivityStatusEnum.Completed$

# Get the starting date from where we are searching
$MAModifiedDay = (Get-date).Adddays(-30)

# Get the Criteria Class
$CriteriaClass = "Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectCriteria"

# Define the Filter
$Filter = "Status = '$($MAStatusCompleted.Id)' AND LastModified > '$MAModifiedDay'"

# Create de Criteria Object
$CriteriaObject = new-object $CriteriaClass $Filter, $MAClass

# AssignedUser RelationshipClass
$RelationshipClass_AssignedUser = Get-SCSMRelationshipClass -Name System.WorkItemAssignedToUser$

# Search for Manual Activities, show the Ticket ID and the AssignedTo User's displayname
# Group per AssignedTo User and sort per Count
Get-SCSMObject -criteria $CriteriaObject|
    Select-Object -property Name, @{
        Label="AssignedTo";
        E={
            (Get-ScsmRelatedObject -SMObject $_ -Relationship $RelationshipClass_AssignedUser).displayname
        }
    }|
    Group-Object -Property AssignedTo |
    Sort-Object -Property Count -Descending



2016/03/08

PowerShell/SCSM - Get Manual Activities Completed in the last month

I got an interested question from a reader that asked how he could get all the Manual Activities completed in the last 30 days using one Filter.

I got some trouble working with Get-SCSMObject and multiple conditions in the -Filter parameter, but got it working using the Criteria parameter. Hope this help!


# Import Smlets Module
Import-module -name Smlets

# Get the Manual Activity Class
$MAClass = Get-SCSMClass -Name System.WorkItem.Activity.ManualActivity$

# Get the Manual Activity Completed Status Enumeration
$MAStatusCompleted = Get-SCSMEnumeration -Name ActivityStatusEnum.Completed$

# Get the starting date from where we are searching
$MAModifiedDay = (Get-date).Adddays(-30)

# Get the Criteria Class
$CriteriaClass = "Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectCriteria"

# Define the Filter
$Filter = "Status = '$($MAStatusCompleted.Id)' AND LastModified > '$MAModifiedDay'"

# Create de Criteria Object
$CriteriaObject = new-object $CriteriaClass $Filter, $MAClass

# Search for Manual Activities
Get-SCSMObject -criteria $CriteriaObject

2016/02/23

PowerShell/SCSM - Get the Work Item parent of an Activity


In the last couple of months, I have been busy on some projects involving System Center Service Manager (SCSM), System Center Orchestrator (SCORCH) and Cireson Portal/Asset Management and I had to script a couple of repetitive tasks using PowerShell.

The following solution allows you to retrieve the parent Work Item of an Activity.

This is useful when you are using a Runbook Activity in your workflow that will invoke a Runbook inside System Center Orchestrator.

Example: In the case where you have a Work Item, a Service Request for instance, with bunch of activities (Review Activity (RA), Manual Activity (MA), Runbook Activity (RBA), etc... ). You could have a Runbook Activity (RBA) calling a System Center Orchestrator runbook.



From a SCORCH perspective it would be useful to find which Work Item the runbook activity belongs to if you want to perform some actions on the Work Item itself and other Activities.
Example: Edit the Work Item Title, Add a reviewer, Skip any Activities with a particular stage, etc...

Here is a PowerShell function that can just do this job for you: Get-SCSMWorkItemParent.


2015/01/17

PowerShell/SCSM - Change the Status of a Manual Activity or a Service Request.

Using the PowerShell module SMlets you can easily change the Status of a Ticket inside System Center Service Manager.

Here are the small bits of code to change the Status of a Manual Activity and a Service Request.


# Import the module
Import-Module -Name smlets

# Get a specific manual activity
$ManualActivity = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.Activity.ManualActivity$) -filter "ID -eq MA51163"
# Change the status of the Manual Activity
Set-SCSMObject -SMObject $ManualActivity -Property Status -Value Completed

# Get a specific Service Request
$ServiceRequest = Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.ServiceRequest$) -filter "ID -eq SR51160"
# Change the status of the Service Request to Completed
Set-SCSMObject -SMObject $ServiceRequest -Property Status -Value Completed


2014/09/09

PowerShell/SCSM - Finding the GUID of an object

Retrieving the GUID of an object in SCSM using PowerShell is sometime a bit challenging. For the WorkItems, this piece of information is not present in any Property available, you have to invoke the get_id method to retrieve it.

There is an 'ID' property which is misleading, it contains the number of the request, for example IR123456.

And for some other type of objects, such as the DomainUser or Enumeration objects the GUID is the..... ID property.

2014/09/08

PowerShell/SCSM - Install and Config the SMlets Module

If you follow my blog, you might have noticed that I recently started to post about SCSM. We just finished to migrate to a new SCSM environment in Azure (Iaas) while using Cireson Portal as a front end.

Of course of lot of the automation part is handled by SCORCH in the background which rely on a lot of PowerShell :-)  (We don't use SMA yet, but I will soon look into it)

Anyway I just wanted to post a quick article on how to configure SMlets on a workstation to be able to query SCSM.

2014/08/24

PowerShell/SCSM - Retrieving Active Directory Object Classes


Following my previous post, today I continue my SCSM journey. I had to create a new automation workflow using SCSM and SCORCH to give the ability to a portal user to add an Active Directory Account to one or more group(s).

Once you get the input of the user, the selected user account and groups impacted by the request are added to the Service Request Related Item, in the Configuration Item field.

Finding this information with PowerShell was not easy. Also Users and Groups are tagged as "User Class" and we want to avoid querying the Active Directory to verify is a user is really a user and a group... really a group object.

2014/08/23

PowerShell/SCSM - My first steps

I recently started to work with System Center Service Manager 2012 R2 (also known as SCSM) which provides provides an integrated platform for automating and adapting an organization's IT service management best practices, such as those found in Microsoft Operations Framework (MOF) and Information Technology Infrastructure Library (ITIL). It provides built-in processes for incident and problem resolution, change control, and asset lifecycle management.