Using SMLets Beta 3 Post #9–Deleting Objects

Using SMLets Beta 3 Post #9–Deleting Objects

  • Comments 7
  • Likes

We’ve discussed this lots of times before in different blog posts in different forms, but I’ll just put it out here one more time in a condensed form.  You can use SMLets to delete objects from the CMDB.  Here are some examples:

Get-SCSMObject –Class (Get-SCSMClass –Name System.WorkItem.Incident$) | Remove –SCSMObject –Force

That will delete all incidents in the system.  You can use other class IDs like:

  • System.WorkItem.ChangeRequest$
  • System.WorkItem.Problem$

If you need to look up other class IDs you can run a cmdlet like this:

Get-SCSMClass | FT Name

You can also filter the results of the Get-SCSMObject cmdlet if you only want to delete certain objects.  For example:

Get-SCSMObject –Class (Get-SCSMClass –Name System.WorkItem.Incident$) –Filter “Title –eq ‘Some title’”| Remove–SCSMObject –Force

Get-SCSMObject –Class (Get-SCSMClass –Name System.WorkItem.Incident$) –Filter “Title –like ‘%something%’”| Remove–SCSMObject –Force

Feel free to share your techniques of using these cmdlets with others in the comments.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • @Travis,

    Maybe you can help me please.

    I am trying to generate a list of Incidents that are assigned to a specific person. I can use get-scsmincident to get a list of all incidents created after a certain date (btw, createdafter is great"). However I am unable to leverage the AssignedTo NotePoroperty. If I use get-scsmObject With System.WorkIncident.Incident$, I am unable to find the correct property to use for "AssignedTo".

    Any help or nudge in the correct direction would be greatly appreciated.

  • Hello Travis,

    The filters as you did won't work for me.. I was doing like this:

    Get-SCSMObject –Class (Get-SCSMClass –Name System.WorkItem.Incident$) –Filter "ID –eq 'IR293'"

    I made them work doing like this:

    Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.Incident$) | where{$_.ID -eq "IR293"}

    Would you know why?

    Thanks once again!!

  • @Gerson,

    This is just a hunch but, have you checked your dashes?

    Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.Incident$) -Filter "ID -eq IR293"

    I'd never use the 2nd option as you'd be loading ALL incidents in memory and then filtering them out the get the one you need. With the first option you'd only be retrieving one single incident from the CMDB.

  • @German Minicucci,

    Thanks for your explanation!

    The quotes were messing it up indeed!!

    I owe you one ;)

  • Hi Travis, Make informed and the process was effective, and shows no incidents in both the operators console as the administrator, but at the time of these reports if they are appearing, how do I completely eliminate incidents and not loaded at the time of make reports. would have to run this command on the reporting server?

  • IN the example above, I think the correct syntax should be "Remove–SCSMObject" as one word vs. "Remove –SCSMObject" with a space in the middle.  The command "Remove" along results in an error.

  • This command worked for SMLets Beta 4

    Remove all incidents: ($ and space removed)

    1. Get-SCSMObject –Class (Get-SCSMClass –Name System.WorkItem.Incident) | Remove –SCSMObject –Force

    Removing Service requests:

    2.Get-SCSMObject –Class (Get-SCSMClass –Name System.WorkItem.ServiceRequest) | Remove –SCSMObject –Force

    Removing Problems:

    3.Get-SCSMObject –Class (Get-SCSMClass –Name System.WorkItem.Problem) | Remove –SCSMObject –Force