No announcement yet.

Auto Shutdown Script w/ AD

  • Filter
  • Time
  • Show
Clear All
new posts

  • Auto Shutdown Script w/ AD

    Is there any way to apply this script to the default Computer Container in AD?

    On Error Resume Next
    '* Enter the DN of the container you want to base your 
    '* search in excluding the domain name (dc=domain,dc=com)
    '* between the double quotes below. If you want it to
    '* search the root, leave it blank.
    strContainer = "ou=Lab Computers"
    Set objRootDSE = GetObject("LDAP://rootDSE")
    If strContainer = "" Then
        strADsPath = objRootDSE.Get("defaultNamingContext")
        strADsPath = strContainer & "," & objRootDSE.Get("defaultNamingContext")
    End If
    Set objConnection = CreateObject("ADODB.Connection")
    objConnection.Open "Provider=ADsDSOObject;"
    Set objCommand = CreateObject("ADODB.Command")
    objCommand.ActiveConnection = objConnection
    objCommand.CommandText = _
        "<LDAP://" & strADsPath & ">;" & _
            "(objectCategory=computer)" & _
    Set objRecordSet = objCommand.Execute
    While Not objRecordSet.EOF
        ShutdownComputer objRecordSet.Fields("Name")
    Sub ShutdownComputer(strComputer)
        set objShell = CreateObject("WScript.Shell") 
    '----Below, remove the single quote -> ' <- from in front of the tool you want to use----
        objShell.Run "shutdown -s -t 90 -f -m \\" & strComputer
    '    objShell.Run "psshutdown.exe \\" & strComputer & " -k -f -t 90"
    End Sub


  • #2
    Re: Auto Shutdown Script w/ AD

    Scripts are either:

    Legacy - set at the user object level and stored in the netlogon share of each DC.


    AD based - Set in a GPO at the OU level and stored in the appropriate folder in the sysvol folder on each DC.

    Legacy scripts cannot be set on a computer object and AD based scripts cannot be set on containers as GPO's can be applied to OU's, not containers, users, or groups.

    If you want to apply a script to a computer(s) then you will have to create an OU for that computer(s), move the computer(s) object to that OU, Create and link a GPO to the OU, and finally create your script and set it as a start up or shut down script in the Computer Configuration portion of the GPO.


    • #3
      Re: Auto Shutdown Script w/ AD

      I use the script as a Scheduled Task nightly. I ended up changing OU=Lab Computers to CN=Computers and it shuts down all the computers in CN, that way any I want to exclude can be moved to a custom OU, where as, by default all other computers are shut down every night. Thanks for your help tho!


      • #4
        Re: Auto Shutdown Script w/ AD

        Hi bronzini, I see you found that script useful. Good to know.

        Yes, you can run that script against any container in AD but of course there needs to be computer objects in the container.

        What Joe thought you were talking about was assigning the script to run from computers in the default computer container. (BTW Joe - the default domain policy does apply to the Computers container so it is possible to assign a script that way)

        Network Consultant/Engineer
        Baltimore - Washington area and beyond