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
Leave a comment