How to get a user that marked a manual activity as completed in SCSM

Last week one of our customers asked how to get a person who actually completed a manual activity. After some investigation, I’ve realized that the only source of that information is a history log of the manual activity. It is a luck that SMlets has a commandlet named Get-SCSMObjectHistory. After some testing, I finished with this code:

import-module smlets

# set ID for a manual activity
$MA_Id = "MA235"

# get the manual activity
$MA = Get-SCSMObject -class (Get-SCSMClass -name System.WorkItem.Activity.ManualActivity) -filter "Id -eq $MA_Id"

#get-history
$h = Get-SCSMObjectHistory -Object $MA

# get a user name that completed MA
foreach ($case in $h.history.GetEnumerator()) {foreach ($change in $case.changes | where-object{$_.newvalue -like "ActivityStatusEnum.Completed"}) {$case.UserName}}

Reposted from our blog.

Cheers!

12 thoughts on “How to get a user that marked a manual activity as completed in SCSM

  1. masood

    Thanks for this above blog,

    i am new to SCSM,

    Could you please show me the script for all service request who are completed manual activity not only single SR

  2. masood

    Dear Marat,

    first of all thank you very much for prompt reply.

    yes, i need user name for every manual activity.

    Regards,

    Mir

  3. masood

    Dear marat

    Actually In my environment we assign an Activity to a group and someone in the group completes the activity. we need to track the user who completed this activity.

    thanks in advance

    Regards,

    Mir

  4. Marat Kuanyshev Post author

    OK, it might seem a bit complicated for you 🙂

    Get-SCSMObject -class (Get-SCSMClass -name System.WorkItem.Activity.ManualActivity) -filter "Status -eq 9de908a1-d8f1-477e-c6a2-62697042b8d9" | %{Write-Host "`r`n`r`nManual activity" $_.id "resolved by:"; Get-SCSMObjectHistory -Object $_ } | %{$_.history.GetEnumerator()} | % {foreach ($change in $_.changes | where-object{$_.newvalue -like "ActivityStatusEnum.Completed"}) {$_.UserName}}

     

  5. masood

    Dear Marat,

    Thanks alot.

    one small question here, can we specify the duration here. ( like from last month to this month Etc)

    Regards,

    Mir

  6. Marat Kuanyshev Post author

    Well, try this:

    $startdDate = Get-Date "1/1/2016"
    $endDate = Get-Date "2/1/2016"
    Get-SCSMObject -class (Get-SCSMClass -name System.WorkItem.Activity.ManualActivity) -filter "Status -eq 9de908a1-d8f1-477e-c6a2-62697042b8d9" | ?{$_.CreatedDate -ne $null -and $_.CreatedDate -gt $startdDate -and $_.CreatedDate -lt $endDate}  | %{Write-Host "`r`n`r`nManual activity" $_.id "resolved by:"; Get-SCSMObjectHistory -Object $_ } | %{$_.history.GetEnumerator()} | % {foreach ($change in $_.changes | where-object{$_.newvalue -like "ActivityStatusEnum.Completed"}) {$_.UserName}}

     

  7. masood

    Dear Marat,

    Thank you very much for your great support.

    the script with dates are working perfectly.

    Actually i am new to service manager and recently we deployed and we are facing lot of issues, due to some issues with dataware house our reporting is not working so i am using script to provide some reports to management.

    Marat, in this script can you please add Title, support group, created date and status so that i will save in excel file.

    Appreciate your great support please.

    Regards,

    Masood

     

  8. Marat Kuanyshev Post author

    Dear Masood,

    I can do that but if you are in SCSM, it might be better to invest some time in the matter. It will pay you back!

    Best regards,

    Marat

  9. masood

    Dear Marat,

    I agreed with you.

    Thank you very much for your great support.

    I am trying to customized the script to get the data.

    Regards,

    Mir

  10. masood

    Dear marat,

    I tried but failed to relate the MA activity with SA to get the title information.

    I am still getting the MA title information.

    Regards,

    mir

  11. masood

    Dear Marat,

    Could you please support me.

    I am trying but i am very week in scripting, please.

    Regards,

    Mir

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.