Using SMLets Beta 3 Post #7–Deleting Any Object in the UI

Using SMLets Beta 3 Post #7–Deleting Any Object in the UI

  • Comments 2
  • Likes

Sometimes you just want to delete an object in the UI.  That’s easy to do with a console task that uses SMLets.  Here’s how:

First, go to the Library/Tasks view.

Click Create Task.

Give the task a name, description (optionally), choose the Object class as the target class, and choose an MP to store the task in.

image

SKip the Categories page (don’t select anything).

On the command line page just use PowerShell.exe as the executable and then enter the following as the parameters:

image

-NoExit -Command "Import-Module SMLets;Get-SCSMObject -Class (Get-SCSMClass -Name System.Entity) -Filter 'DisplayName -eq "$Context/Property[Type='CustomSystem_Library!System.Entity']/DisplayName$"' | Remove-SCSMObject -Force -Confirm"

NOTE:  Do not just simply copy/paste the above.  You need to actually select the DisplayName property using the Insert Property button. Otherwise the necessary MP references will not be created behind the scenes.

Update [June 20, 2011] - I've changed this in the 7.0.6555.1 version of the MP to use the FullName instead of the DisplayName since display names that had quotes or double quotes in them were throwing off the parameter sequence.  The best way to handle this would be to pass the ID, but we need to add support to the Get-SCSMObject cmdlet in SMLets to allow a GUID ID to be passed in first.  For now FullName will do the trick.  FullName is the class name + : + the key property values (which would rarely if ever contain a quote or double quote).

The new command looks like this.  Note: you can't use the Insert button to insert the $Context/?$FullName$? - you'll need to just type that in or copy paste it from here:

-NoExit -Command "Import-Module SMLets; Get-SCSMObject -Class (Get-SCSMClass -Name System.Entity) -Filter 'FullName -eq "$Context/?$FullName$?"' | Remove-SCSMObject -Force -Confirm"

Click Next, Create, Close.

Now you will have a new console task in the actions pane on any view in the work items and configuration items workspaces when you have an object selected.

image

When you click on it a PowerShell window will pop up and confirm that you want to delete the object.  It will first prompt you if you want to delete the object and then it will ask you to commit it.  I don’t know why it does the second prompt but whatever, better safe than sorry I guess.  You need to respond Y to both.

image

BE VERY CAREFUL USING THIS TASK.  THERE IS NO UNDO!

This requires SMLets of course.  You can download it here and install it on all your console machines.

Only administrators will be able to use this task but anybody can see it unless you use user roles to scope away visibility of this task.

If you want to make this task available on a subset of classes instead of all, you can just choose a different target like the incident class, computer class, etc.

I’ve uploaded the management pack for this to the SCSM Gallery on TechNet.

http://gallery.technet.microsoft.com/Task-to-Delete-Object-from-99b7beb0

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • how do i delete multiple objects? when i select multiple objects the delete object task disappears.

  • @Vance -

    This solution only deletes objects one at a time.  In order to do bulk deletion you would need to create a custom console task in code.

    Another alternative though is to use Remove-SCSObject from SMLets.  Search for it on Bing and you will see some examples of using it.