Affected user is not anymore an employee

Apr 22, 2012 at 5:23 AM

Hello guys...I'm really new on this, but I'm learning fast ;) I hope you can help me..I have this situation...

There are several Active incidents related to users that are not longer company employees. So basically the idea is to run an ps script including as a parameter the Incident Affected User so all the ACTIVE and RESOLVED related incidents will be automatically changed to closed.

I was exploring and trying something like this...but I bealive is not optimized...and probably is not sure to put into a production envirnonment. 

get-scsmtypeprojection System.WorkItem.Incident.ProjectionType|Get-SCSMObjectProjection|?{$_.AffectedUser -like '*George Bush*'}|%{$_.object}|set-SCSMIncident -Status Closed

Problems:

*I cant find the way to replace the -like for some to expres equal doing a faster query and a correct match

*I cant add the Status to avoid include already Closed incident in the object protection filters

*finally, the performance I'm getting is really bad...and I have only 5000 incidents in my test db.

Thanks - Gus

Developer
Apr 25, 2012 at 7:34 AM

first, you should use a different projection. The System.WorkItem.Incident.ProjectionType carries a lot more than you need, and with all those additional relationships, the amount of data that will be returned could be massive. You also need the script I wrote some time ago for building a projection criteria which didn't seem to make it into the smlets module (http://jtruher3.wordpress.com/2011/05/13/retrieving-projection-data-with-criteria/). You'll need to save that script and use it:

here's an example:

 

PS# $projection = get-scsmtypeprojection System.WorkItem.Incident.View.ProjectionType|select -first 1
PS# $projection

ProjectionType: System.WorkItem.Incident.View.ProjectionType
ProjectionSeed: System.WorkItem.Incident
Components:
   Alias                          TargetType         TargetEndPoint
   -----                          ----------         ---------------
   AffectedUser                   System.User        RequestedWorkItem
   AssignedUser                   System.User        AssignedWorkItem

PS# get-scsmobjectprojection -Projection $projection

Id          Title                                           AssignedTo        Status  Priority AffectedUser         LastModified
--          -----                                           ----------        ------  -------- ------------         ------------
CustomIR276 Nihil iriure sanctus gubergren invidunt commodo Luptatum Sanctus  Closed         2 Id Amet              3/24/2012 11:14:23 PM
CustomIR274 At laoreet vulputate voluptua vel accumsan      Velit Sea         Pending        9 Vero Enim            3/24/2012 11:14:23 PM
CustomIR277 Aliquam invidunt stet nonumy dolores duo        Velit Sea         Pending        1 Id Amet              3/24/2012 11:14:23 PM
CustomIR279 Voluptua gubergren eos in accusam elitr         Invidunt Sea      Active         1 Stet Sit             3/24/2012 11:14:23 PM
CustomIR273 Esse erat facilisis kasd id consequat           Aliquyam Volutpat Closed         6 In Eum               3/24/2012 11:14:23 PM
CustomIR282 Ut rebum gubergren diam diam duo                Stet Sit          Pending        2 Stet Sit             3/24/2012 11:14:23 PM
CustomIR281 Dolor clita voluptua wisi elitr aliquam         Vero Enim         Pending        2 JWT-D4.Administrator 3/24/2012 11:14:23 PM
CustomIR280 Illum ut minim velit no sit                     Accusam Justo     Pending        2 Velit Sea            3/24/2012 11:14:23 PM
CustomIR275 Eos dignissim congue imperdiet dolore ea        In Eum            Active         2 Luptatum Sanctus     3/24/2012 11:14:23 PM
CustomIR278 Clita sed accusam accusam dolor labore          Velit Sea         Closed         3 Invidunt Sea         3/24/2012 11:14:23 PM
PS# $criteria = new-scsmProjectionCriteria.ps1 -projection $projection -filter "AffectedUser.DisplayName -eq 'Stet Sit'"
PS# Get-SCSMObjectProjection -Criteria $criteria
Id          Title                                   AssignedTo   Status  Priority AffectedUser LastModified
-- ----- ---------- ------ -------- ------------ ------------
CustomIR279 Voluptua gubergren eos in accusam elitr Invidunt Sea Active 1 Stet Sit 3/24/2012 11:14:23 PM
CustomIR282 Ut rebum gubergren diam diam duo Stet Sit Pending 2 Stet Sit 3/24/2012 11:14:23 PM

 

 


 

Then, once you've got to this point, you can set the closed state:

PS# Get-SCSMObjectProjection -Criteria $criteria | %{$_.object}|set-scsmobject -PropertyHashtable @{ Status = "Closed" }
(which sets the status, and below is the proof :^)
PS# Get-SCSMObjectProjection -Criteria $criteria

Id          Title                                   AssignedTo   Status Priority AffectedUser LastModified
--          -----                                   ----------   ------ -------- ------------ ------------
CustomIR279 Voluptua gubergren eos in accusam elitr Invidunt Sea Closed        1 Stet Sit     4/24/2012 11:31:17 PM
CustomIR282 Ut rebum gubergren diam diam duo        Stet Sit     Closed        2 Stet Sit     4/24/2012 11:31:16 PM

Also, you should be able to provide a two part criteria:

$criteria = new-scsmProjectionCriteria -projection $projection -filter "AffectedUser.DisplayName -eq 'Stet Sit' -and Status -ne 'Closed'"

which will further reduce the amount of retrieved data

 

jim

Apr 25, 2012 at 11:40 AM

Thanks Jim, I'll try it today an let you know. Thank you very much for your time and the help!

Gus