This Vbs script will allow you to enter a machine name and delete it from the SMS database. It will prompt you for the Site Server Name, Site Code and Machine name. It will then attempt to determine the ResourceId for the machine and if it is found delete the machine from the SMS database.
To remove a list of machines from the SMS database see my previous post:
Delete Machines From SMS And Send The Results To Excel
http://myitforum.com/cs2/blogs/dhite/archive/2006/09/17/Delete-Machines-From-SMS-And-Send-The-Results-To-Excel.aspx
Vbs Script:
strServer = InputBox("Enter Site Server Name")
strSiteCode = InputBox("Enter Site Code")
strComputer = InputBox("Enter Machine Name To Delete")
Set locator = CreateObject( "WbemScripting.SWbemLocator" )
Set WbemServices1 = locator.ConnectServer( strServer,"root\SMS\site_" & strSiteCode)
ResID = getResID(strComputer, WbemServices1)
If ResID = Empty Then
MsgBox "Unable To Determine The ResourceId For " & strComputer & " Exiting Application"
Wscript.Quit
Else
MsgBox "The ResourceId For " & strComputer & " On " & strServer & " Is " & ResID
End If
Set sResource = WbemServices1.Get("SMS_R_System='" & ResID & "'")
sResource.Delete_
If Err = 0 Then
MsgBox strComputer & " Has Been Removed From " & strSiteCode
MsgBox "Unable To Locate " & strComputer & " On " & strServer
Set sResource = Nothing
Function GetResID(strComputer, oWbem)
strQry = "Select ResourceID from SMS_R_System where Name=" & "'" & strComputer & "'"
Set objEnumerator = oWbem.ExecQuery(strQry)
If Err <> 0 Then
GetResID = 0
Exit Function
For Each objInstance in objEnumerator
For Each oProp in objInstance.Properties_
GetResID = oProp.Value
Next
Set objEnumerator = Nothing
End Function
No Comments