Ask a questionAsk a question
 

General DiscussionHere is script to delete drivers

  • Wednesday, October 22, 2008 4:34 PMShawn Nelson Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

     

     


All Replies

  • Friday, November 14, 2008 10:52 AMchiners_68 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Note :- Do not run on workstation with SCCM Admin console you will just get errors.

     

    I run this on my primary site server & although it used nearly 100% CPU after about 5 mins it reprted it "Deleted xxx drivers succesfully" & CPU then restored to normal.

     

     

  • Wednesday, November 19, 2008 10:11 PMpcgeek86 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Just an idea ... you could simplify your code by changing your query to: select * from sms_driver where IsEnabled = '0' and then avoid having to use the If .. Then statement to determine the criteria to delete.

    Trevor Sullivan
    Systems Engineer
  • Tuesday, December 09, 2008 4:31 PMDewNut Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    worked for me.  thanks for the script.  saved me an hour.

     

  • Wednesday, May 27, 2009 9:11 PMaacajo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Didn't work for me.

    SwbemObjectEx: Generic Failure

    Looks like it is complaining about this line:

    driver.delete_

    Any ideas?
  • Friday, June 05, 2009 12:43 PMpcgeek86 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    aacajo,

    You'd have to provide a little more specific information about the error. What is the message you're getting? Can you post a screenshot on tinypic.com or something?

    Trevor Sullivan
    Systems Engineer
    OfficeMax Corporation
    Trevor Sullivan Systems Engineer OfficeMax Corporation
  • Friday, June 26, 2009 3:05 PMeobiont Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Me too.  I saw this script elsewhere and thought it was not working.  I added a wscript.echo driver.localizedDriverName in the for loop and then saw that it was just taking 20-30 seconds per driver deletion to run on my system.  so 90 driver deletions is going to take 40 minutes.  Maybe not faster than by hand, but certainly easier. 
  • Friday, June 26, 2009 3:08 PMpcgeek86 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    eobiont,

    That seems like an abnormally long time to delete each driver. I'm pretty sure mine delete within a few seconds, each.

    Trevor Sullivan
    Systems Engineer
    OfficeMax Corporation
    Trevor Sullivan Systems Engineer OfficeMax Corporation