Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete machines with a vbs script

Status
Not open for further replies.

PAP

MIS
Apr 10, 2000
14
0
0
CH
Does someone have a script in order to purge a list of machines from SMS with WMI.
Thanks a lot,

Pierre-Alain Pilet
Informatique Technique et Projets
BOBST SA

 
If I understand your question correctly, you may be able to accomplish this by creating a direct membership collection then performing a delete special on the collection.
 
Sorry for misanderstanding. My question was about a vbs script. I found this example:

'*******************************************************************************
'Name.............: Del_SMS_record.vbs
'Date.............: 04/05/02
'Author...........: Manohar Mathan
'Function.........: Deletes resource from Site Server
'Usage............: cscript Del_SMS_record.vbs computername

' OR

' Double click on script, it will prompt you for COmputerName
' Can be used in a 'FOR' statement to delete multiple computers.
'
'Please mail questions/Comments to mkannan15@yahoo.com

'*******************************************************************************

Dim loc
Dim oArgs
Dim strComputer, ResID
Dim strServer, strSiteCode

'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'Edit the next two lines for your sitecode and siteserver
strServer = "SER2"
strSiteCode = "BSA"
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


If strServer = "ServerName" Then
WScript.Echo "Edit the script to enter ServerName and Site Code information"
WScript.Quit
End If

Set oArgs = WScript.Arguments
If oArgs.Count = 1 Then
strComputer = oArgs(0)
Else
strComputer = InputBox("Enter the Computer Name to be deleted from SMS:", _
"Computer Name", strComputer)
End If

Set loc = CreateObject( "WbemScripting.SWbemLocator" )
Dim WbemServices1
Set WbemServices1 = loc.ConnectServer( strServer,"root\SMS\site_" & strSiteCode)

ResID = getResID(strComputer, WbemServices1)
If ResID = Empty Then
WScript.Echo "Could not get ResourceID for " & strComputer
End If
WScript.Echo strComputer & " ResourceID in ALBSMSPRI01 is " & ResID

Set sResource = WbemServices1.Get("SMS_R_System='" & ResID & "'")
sResource.Delete_ 'Delete the resource
If Err = 0 Then
WScript.Echo strComputer & " deleted from ALBSMSPRI01"
Else
WScript.Echo strComputer & " COULD NOT BE deleted from " & strServer
End If

Set sResource = NOTHING

'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function GetResID(strComputer, oWbem)

Dim strQry

strQry = "Select ResourceID from SMS_R_System where Name=" & "'" & strComputer & "'"
Set objEnumerator = oWbem.ExecQuery(strQry)
If Err <> 0 Then
GetResID = 0
WScript.Echo &quot;error Getting ResourceID of &quot; & strComputer
Exit Function
End If

For Each objInstance in objEnumerator
For Each oProp in objInstance.Properties_
GetResID = oProp.Value
WScript.Echo &quot;Resource ID of &quot; & strCOmputer & &quot; is &quot; & oProp.Value
Next
Next

Set objEnumerator = NOTHING
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top