用过System Center Service Manager的人应该知道,SCSM中有大量的Workitem,默认情况下是无法删除的,并且每个项目的ID编号会越来越大,但是作为ID人员,我们很多的Service Request等需要多次的测试和调试,在测试中生成的很多项目都是无效的或者无用的,下面就讲一下怎么删除这些无效的项目。


首先需要在SCSM服务器上安装SMLets库,这个库提供了更多的SCSM的Powershell语句和功能。

下载链接:http://smlets.codeplex.com/releases/view/84853.


之后只需要打开Powershell输入命令既可以删除相关类型的事件条目


清除Incident类的事件:

Import-Module SMLets
Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.Incident$) | Remove-SCSMObject -Force -Confirm


清除Changes类的事件:

Import-Module SMLets
Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.ChangeRequest$) | Remove-SCSMObject -Force -Confirm


清除Activities类的事件:

Import-Module SMLets
Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.Activity$) | Remove-SCSMObject -Force -Confirm


清除Problems类的事件:

Import-Module SMLets
Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.Problem$) | Remove-SCSMObject -Force -Confirm


清除Service Request类的事件:

Import-Module SMLets
Get-SCSMObject -Class (Get-SCSMClass -Name System.WorkItem.ServiceRequest$) | Remove-SCSMObject -Force -Confirm


下面讲一下如何重置ID编码:


首先登陆到Service Manager的数据库中:


输入下面语句:

select * from AutoIncrementAvailableRange

如下图:

wKiom1POGpHS5Jv7AAFjG7sw7-M598.jpg

看不懂没关系,我们再输一条:

Select MT.TypeName,MT.ManagedTypeId,MTP.ManagedTypePropertyName,MTP.ManagedTypePropertyID,AIAR.FirstAvailableValue

from ManagedType as MT, ManagedTypeProperty as MTP, AutoIncrementAvailableRange as AIAR

where MT.ManagedTypeId = AIAR.ManagedTypeId and MTP.ManagedTypePropertyId = AIAR.ManagedTypePropertyId

wKioL1POHbXB-BavAAC_66JNlfE481.jpg

可以发现,所有项目的编号,其实就是根据这个表中最后一行的数据来编码的,也就是说,如果想让Incident的ID数字从1重新开始,就修改:

update AutoIncrementAvailableRange

set FirstAvailableValue = 1     

where ManagedTypeId = 'F59821E2-0364-ED2C-19E3-752EFBB1ECE9' and ManagedTypePropertyId = '28B1C58F-AEFA-A449-7496-4805186BD94F'


注意!为了避免重复ID,重置数据前,一定先用上面的SMLets命令清空项目。