Home Service Manager

Script to clear off Failed workflows

Brian_WiestBrian_Wiest Customer Super IT Monkey ✭✭✭✭✭
Looking if anyone has a script to clear all failed workflows.
Thanks

Best Answer

  • Conner_WoodConner_Wood Advanced IT Monkey ✭✭✭
    edited April 2017 Accepted Answer
    I never did get around to doing this, however I know you'll need to look into Microsoft.EnterpriseManagement.Subscriptions section.

    I assume with C# this would work when referencing the Microsoft.EnterpriseManagement.Core.dll:

    using Microsoft.EnterpriseManagement;
    using Microsoft.EnterpriseManagement.Subscriptions;
    
    ~~~~~~~~~~~~
    
    EnterpriseManagementGroup emg = new EnterpriseManagementGroup("SCSMSERVER");
    IWorkflowSubscriptionBase wfSub = emg.Subscription.GetSubscriptionsByCriteria(new ManagementPackRuleCriteria("Name LIKE '%'")).FirstOrDefault();
    
    //All
    //IList<SubscriptionJobStatus> wfSubInstances = emg.Subscription.GetSubscriptionStatusById(wfSub.Id.Value);
    
    //Failed
    IList<SubscriptionJobStatus> wfSubFailedInstances = emg.Subscription.GetFailedSubscriptionStatusById(wfSub.Id.Value);
    
    
    //FOR EACH THROUGH THEM AND IGNORE!
    foreach(SubscriptionJobStatus wfSubFailedInstance in wfSubFailedInstances)
    {
         emg.Subscription.IgnoreFailedSubscription(wfSubFailedInstance);
    }
    
    


    With PowerShell I know only this ;)

    $wfSubs = Get-SCSMSubscription -ErrorAction SilentlyContinue


Answers

  • Conner_WoodConner_Wood Customer Advanced IT Monkey ✭✭✭
    edited April 2017 Accepted Answer
    I never did get around to doing this, however I know you'll need to look into Microsoft.EnterpriseManagement.Subscriptions section.

    I assume with C# this would work when referencing the Microsoft.EnterpriseManagement.Core.dll:

    using Microsoft.EnterpriseManagement;
    using Microsoft.EnterpriseManagement.Subscriptions;
    
    ~~~~~~~~~~~~
    
    EnterpriseManagementGroup emg = new EnterpriseManagementGroup("SCSMSERVER");
    IWorkflowSubscriptionBase wfSub = emg.Subscription.GetSubscriptionsByCriteria(new ManagementPackRuleCriteria("Name LIKE '%'")).FirstOrDefault();
    
    //All
    //IList<SubscriptionJobStatus> wfSubInstances = emg.Subscription.GetSubscriptionStatusById(wfSub.Id.Value);
    
    //Failed
    IList<SubscriptionJobStatus> wfSubFailedInstances = emg.Subscription.GetFailedSubscriptionStatusById(wfSub.Id.Value);
    
    
    //FOR EACH THROUGH THEM AND IGNORE!
    foreach(SubscriptionJobStatus wfSubFailedInstance in wfSubFailedInstances)
    {
         emg.Subscription.IgnoreFailedSubscription(wfSubFailedInstance);
    }
    
    


    With PowerShell I know only this ;)

    $wfSubs = Get-SCSMSubscription -ErrorAction SilentlyContinue


Sign In or Register to comment.