shutdown computers in OU

Discussion in 'Scripting' started by Tom, Mar 2, 2009.

  1. Tom

    Tom Guest

    hi,
    does anyone have script for shutdown computers in certain OU in one domain?
     
    Tom, Mar 2, 2009
    #1
    1. Advertisements

  2. Tom

    Masterplan Guest

    Hi Tom,

    You can export a list of computers from that OU with dsquery or csvde and
    then use the shutdown command.
     
    Masterplan, Mar 2, 2009
    #2
    1. Advertisements

  3. This link shows how to shutdown a computer in VBScript using WMI:

    http://www.microsoft.com/technet/scriptcenter/guide/sas_cpm_evqo.mspx

    As long as you are only concerned with computers directly in the OU (not
    those in any sub OU's), the VBScript program could be similar to:
    =========
    Option Explicit

    Dim objOU, objComputer, objWMIService, colOperatingSystems
    Dim objOperatingSystem, strComputer

    Const SHUTDOWN = 1

    ' Bind to the OU object.
    Set objOU = GetObject("LDAP://ou=Sales,ou=West,dc=MyDomain,dc=com")

    ' Filter on computer objects.
    objOU.Filter = Array("computer")

    ' Enumerate all computers in the OU.
    For Each objComputer In objOU
    ' Retrieve NetBIOS name of computer.
    strComputer = objComputer.sAMAccountName
    ' Strip off the trailing "$".
    strComputer = Left(strComputer, Len(strComputer) - 1)
    ' Bind to the WMI service on the remote computer.
    Set objWMIService = GetObject("winmgmts: {(Shutdown)}" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
    Set colOperatingSystems = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_OperatingSystem")
    For Each objOperatingSystem In colOperationgSystems
    objOperatingSystem.Win32ShutDown(SHUTDOWN)
    Next
    Next
     
    Richard Mueller [MVP], Mar 5, 2009
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.