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.
Enter your email address below and click the Subscribe button to receive email notifications about new and exciting downloads available through our website at https://www.techygeekshome.com
You will also receive notifications about new technical guides, latest news and MSI installer downloads that are available through our blog here at https://blog.techygeekshome.info
We will not spam you and we will not pass on any of your details to anyone else. We tend to post new content once or twice a week.
You can unsubscribe any time you like.