SCSM 2012: Deleting Configuration Items in Bulk in System Center 2012 Service Manager with PowerShell

I recently posted how to delete work items in bulk in System Center 2012 Service Manager (SCSM) and in that post, promised I would post how to do the same with configuration items (CIs)in SCSM as well. As with the work item example, I am using the SMLets, the community-developed supplement to the native cmdlets of the SCSM, which are available at http://smlets.codeplex.com. Here are a couple of examples of bulk deletion of CIs to get you started.

Removing “Pending Delete” CIs in Bulk

SCSM does not automatically delete objects (instances) without administrator permission, but once you have reviewed instances in Pending Delete status, you may want to get rid of them. Here’s a quick sample script:

#Import the SMLets
Import-Module SMlets

#Retrieve Configuration Item Class
$SMClass = Get-SCSMClass | where{$_.name -match “system.configitem”}

#Find CI instances with status ‘Pending Delete’
$SMDelObj = Get-SCSMObject -class $SMClass | where {$_.objectstatus -match “Pending”}

#Delete the CI instances found above
$SMDelObjs | Set-SCSMobject -property objectstatus -value deleted

Forcibly Deleting Active CIs in Bulk

Deleting CIs that are not yet ‘Pending Delete’ (active CIs) is also not a difficult task. You could also delete any CI by class and name (or simply name) if you wanted.

For example, you can delete computers matching the wildcard “SQL*.contoso.com” as shown below. This sample also requires the SMLets mentioned above.

Get-SCSMObject -Class (Get-SCSMClass -Name Microsoft.Windows.Computer$) | `
where-object{$_.DisplayName –like “SQL*.contoso.com“} | remove-scsmobject -force

Additional Resources

Also check out some of the many additional System Center PowerShell related resources on SCC

PowerShell blog category – http://www.systemcentercentral.com/category/blog/powershell/ (and it’s own RSS feed HERE)

Master Collection of System Center PowerShell – http://www.systemcentercentral.com/powershell-scripts-for-system-center-master-collection/

3 thoughts on “SCSM 2012: Deleting Configuration Items in Bulk in System Center 2012 Service Manager with PowerShell

  1. Profile photo of andreandre

    Pending delete, for 2012 R2 I modified it to:

    Import-Module ‘C:\Program Files\Microsoft System Center 2012 R2\Service Manager\PowerShell\System.Center.Service.Manager.psd1’
    $SMClass = Get-SCSMClass | where{$_.name -match “system.configitem”}
    $SMDelObj = Get-SCSMClassInstance -class $SMClass | where {$_.objectstatus -match “Pending”}
    foreach ($A in $SMDelObj)
    { $A.Remove()}

     

     

  2. Profile photo of BeigewellBeigewell

    Although I can successfully run this it doesn’t seem to delete anything! I ran it on my test system and worked like a charm. Then move to Production which will not display Deleted Items at all and although it ran I still cannot access deleted items view. It takes a long time to load then errors out with the following:

    An exception was thrown while processing GetManagedEntitiesByManagedEntityTypesAndCriteriaWithInstanceQueryOptions for session ID uuid:b687fddd-feab-4534-ade0-25553e485ed5;id=5.
    Exception message: The creator of this fault did not specify a Reason.
    Full Exception: System.ServiceModel.FaultException`1[Microsoft.EnterpriseManagement.Common.UnknownDatabaseException]: The creator of this fault did not specify a Reason. (Fault Detail is equal to The query processor ran out of internal resources and could not produce a query plan. This is a rare event and only expected for extremely complex queries or queries that reference a very large number of tables or partitions. Please simplify the query. If you believe you have received this message in error, contact Customer Support Services for more information.).

    If I run get-scsmdeleteditems it returns the same error and I am now at a loss as to how to resolve this.

  3. Pingback: SCSM Bulk deleting of Deleted Items | Artem_Pro Blog

Leave a Reply