Remove-SCSMObject questions

Aug 12, 2010 at 6:09 PM

Here's the scenario:

I'd like to clear out all of our change requests / Incidents or possibly a subset of them (I'd really like to test it with one or two individually before blowing them all away).  I've tried several different methods but I think I need to be feeding a different type of object into Remove-SCSMObject.  Here's what I've been trying:

Remove-SCSMObject System.WorkItem.ChangeRequest

Remove-SCSMObject : Unable to cast object of type 'System.String' to type 'Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject'.At line:1 char:18+ Remove-SCSMObject <<<<  System.WorkItem.ChangeRequest    + CategoryInfo          : NotSpecified: (:) [Remove-SCSMObject], InvalidCastException    + FullyQualifiedErrorId : System.InvalidCastException,SMLets.RemoveSMObjectCommand

.. and variations of that.  What am I missing here?  Looking at the help on Remove-SCSMObject it looks like it is expecting a <PSObject> or possibly a SMObject.

Some examples would be great!  Perhaps one that only deletes a specified record by ID or Display Name.  Thanks.

Developer
Aug 13, 2010 at 1:33 AM
Edited Aug 13, 2010 at 1:36 AM

sorry about the missing examples, I know that's a problem. I will be providing examples as I can.

As for this specific issue, the Remove-SCSMObject was built to take a stream of objects as pipeline input, so to make this work, try:

PS> Get-SCSMObject System.WorkItem.ChangeRequest$ | Remove-SCSMObject

That should do it. Please note that you have to use the "$" in the name. This is because the code for grabbing an object from a string is greedy, and will find instances of *ALL* objects whose class contains System.WorkItem.ChangeRequest which will include the following:

PS> get-scsmclass system.workitem.changerequest

Abstract Name
-------- ----
False    System.WorkItem.ChangeRequest.InternalWorkflowTarget
False    System.WorkItem.ChangeRequest
False    System.WorkItem.ChangeRequest.WorkflowTarget

If you need to filter the objects, then you can do this on the retrieval side (in my case I don't have any change requests, but here's how you could do it with users)

PS> get-scsmobject Microsoft.AD.User$ -Filter "Firstname -eq 'Phil'"

Type                                             DisplayName
----                                             -----------
System.Domain.User                               Phil Otten


PS> get-scsmobject Microsoft.AD.User$ -Filter "Firstname -eq 'Phil'" | remove-scsmobject -whatif
What if: Performing operation "Remove-SCSMObject" on Target "WOODGROVE.potten".
What if: Performing operation "Remove-SCSMObject" on Target "Delete all instances".
PS>

You'll note that I first found out what the filter would remove and then another command to remove them (you'll also notice that I didn't actually remove the user, but you can :) )

I hope that helps! 

jim

 

Aug 13, 2010 at 5:27 PM

Thanks for the help, I'll give that a shot.

Aug 13, 2010 at 7:46 PM

Hmmm... I'm getting some errors when trying this:

 

PS C:\windows\system32\WindowsPowerShell\v1.0\Modules\SMLets> Get-SCSMObject System.WorkItem.ChangeRequest$ | Remove-SCSMObject

Remove-SCSMObject : This object cannot be marked for deletion because it is not derived from System.ConfigItemAt line:1 char:66+ Get-SCSMObject System.WorkItem.ChangeRequest$ | Remove-SCSMObject <<<<    + CategoryInfo          : ObjectNotFound: (CR17: Acrobat for Windows (Upgrade):EnterpriseManagementObject) [Remove   -SCSMObject], NullReferenceException    
+ FullyQualifiedErrorId : ObjectStatus Property,SMLets.RemoveSMObjectCommand

Remove-SCSMObject : This object cannot be marked for deletion because it is not derived from System.ConfigItemAt line:1 char:66+ Get-SCSMObject System.WorkItem.ChangeRequest$ | Remove-SCSMObject <<<<    + CategoryInfo          : ObjectNotFound: (CR2269: Minor Change Request:EnterpriseManagementObject) [Remove-SCSMOb   ject], NullReferenceException
 + FullyQualifiedErrorId : ObjectStatus Property,SMLets.RemoveSMObjectCommand

 

(and so on for the rest of the objects that were supposed to be deleted)

Aug 13, 2010 at 7:52 PM

As a note, I get the same errors when I try to delete all "Incidents" as well.  If I just run the Get-SCSMObject command, it returns all the records as expected, but when piping that to Remove-SCSMObject I get the above errors.

Developer
Aug 13, 2010 at 8:48 PM
Edited Aug 13, 2010 at 10:12 PM

yah - this error comes because what I try to do is to mark the instance as PendingDelete, which is only available on Config.Item and its derivations (I thought I had improved the error message to suggest using -force, I'll track *that* down).

There is an escape hatch, which is to use the -force flag on Remove-SCSMObject which is supposed to handle everything (and also forcibly removes the Config.Item). Hmmm, this tells me a couple of things, first, I really need to put the documentation together and second, perhaps I should try to follow intent, so if you give me a Config.Item derived object I mark it as PendingDelete otherwise just blast it.

jim

Aug 13, 2010 at 10:55 PM
Thanks! That did the trick.
Sep 3, 2010 at 10:51 PM

Another question on filtering:

I'm attempting to return all the objects of source "Operations Manager" by running variations of the following..

Get-SCSMObject System.WorkItem.Incident$ -Filter "Source -eq 'Operations Manager'" 

Error returned:

Get-SCSMObject : Source_96FD9295_16FA_3D7A_5995_F805B7B01F21='Operations Manager' -- Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).At line:1 char:15+ Get-SCSMObject <<<<  System.WorkItem.Incident$ -Filter "Source -eq 'Operations Manager'"    + CategoryInfo          : NotSpecified: (:) [Get-SCSMObject], UnknownDatabaseException    + FullyQualifiedErrorId : Microsoft.EnterpriseManagement.Common.UnknownDatabaseException,SMLets.GetSMObjectCommand

Is it wanting the GUID of the source type "Operations Manager'?  If so, any ideas on where I can find that?

Sep 7, 2010 at 7:19 PM

For anyone that is interested, I ended up just using "ManagementGroupName" instead of "Source", I'm not sure why "Source" didn't work, but this accomplished the same thing:

Get-SCSMObject System.WorkItem.Incident$ | where-object{$_.managementgroupname -eq 'SCOM'} | Remove-SCSMObject -force

Developer
Sep 8, 2010 at 8:14 AM
The issue here is that source is actually an enum and the filtering doesn't convert to an enum to a string when doing this comparison. It would probably worked if you had done the following: Get-scsmobject system.work item.incident$|?{ $_.source.displayname -eq "operations manager"}