sccm logo

If you are using SCCM and you want to delete a device from your database (for example if you are using OSD and only deploying to Unknown Devices) then you would normally have to go into the SCCM Console, Devices, search for the device and then right click and delete the device which would remove it from the SCCM database.

However, you can use a very simple script to carry this out to allow you to give the script to your help desk or OSD teams so that they can quickly and easily delete a device without having to pester your SCCM administrations to carry out this mundane task.

The script you can put together to use is as below:

ON ERROR RESUME NEXT strServer=InputBox("Site Server",,"TGHCM1607") strSiteCode=InputBox("Site Code",,"TGH") strComputer = InputBox("Machine Name To Delete",,"Machine Name") Set locator = CreateObject( "WbemScripting.SWbemLocator" ) Set WbemServices1 = locator.ConnectServer( strServer,"rootSMSsite_" & strSiteCode ResID = getResID(strComputer, WbemServices1) If ResID = Empty Then MsgBox "Cannot Get 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 Else MsgBox "Unable To Find " & strComputer & " On " & strServer End If 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 End If For Each objInstance in objEnumerator For Each oProp in objInstance.Properties_ GetResID = oProp.Value Next Next Set objEnumerator = Nothing End Function

The script can be edited in a number of ways to customise it to your local environment. So, at the moment it is generalised so will ask you to input your site code and site server, you can change this to be hard coded so that all your help desk tech’s will have to do is to enter the machine name.

So once you are happy with the script and tested it in your lab environment (do not blame us if you do not test it and some tech deletes all your devices!) then you can save this as a VBS script and give it out as you see fit.


If you have any comments or questions on this post, then please feel free to leave us a comment below using our comments system.

Click to rate this post!
[Total: 0 Average: 0]

Discover more from TechyGeeksHome

Subscribe to get the latest posts to your email.

Avatar for Andrew Armstrong

Andrew Armstrong

Founder of TechyGeeksHome and Head Editor for over 15 years! IT expert in multiple areas for over 26 years. Sharing experience and knowledge whenever possible! Making IT Happen.

One thought on “SCCM – Delete a Device using VBS

Leave us a message...

This site uses Akismet to reduce spam. Learn how your comment data is processed.