Script to delete drivers in ConfigMgr 2007
Source: http://forums.microsoft.com/TechNet/ShowPost.aspx?siteid=17&PostID=4033763&SiteID=17
I was having problems with corrupt drivers and decided to remove my NIC drivers and re-add them. When I went to delete them I realized with over 100 drivers to delete you have to delete them one by one. This can become a major pain and luckily on this forum there was someone who graciously provided a script that would remove ALL drivers from SCCM. With that being said I didn't want to delete over 1000 drivers and re-add all of them, I only wanted a select few. To help others out there that aren't as script oriented I wanted to share my script that will go through and delete disabled drivers. You can select multiple drivers and just click disable, then run this script and it will clear them out for you. It worked quite nicely for me, and I hope it helps the next person!
Code Snippet
' Connect to the SMS namespace
siteNamespace = GetSiteNamespace()
SET objWMIService = GetObject( "winmgmts:{impersonationLevel=impersonate}!"_
&siteNamespace)
SET drivers = objWMIService.ExecQuery("SELECT * From SMS_Driver")
numDriversDeleted = 0
' Process the results
FOR EACH driver in drivers
IF driver.IsEnabled = 0 THEN
driver.Delete_
numDriversDeleted = numDriversDeleted +1
END IF
NEXT
WScript.Echo "Successfully deleted "&numDriversDeleted&" drivers."
'
' Utility function to search for the site namespace
'
FUNCTION GetSiteNamespace()
' Find SMS Provider
SET objSMSNamespace = GetObject("winmgmts:{impersonationLevel="&_
"impersonate}!\\.\root\sms")
SET results = objSMSNamespace.ExecQuery("SELECT * From "&_
"SMS_ProviderLocation WHERE ProviderForLocalSite = true")
' Process the results
FOR EACH r in results
namespacePath = r.NamespacePath
NEXT
' Fail if we did not find the site
IF namespacePath = "" THEN
WScript.Echo "Failed to locate SMS provider."
WScript.Quit 1
END IF
' Return
GetSiteNamespace = namespacePath
END FUNCTION