Script: Remote shutdown of all domain computers



We realy need a script to automaticaly and remotly shutdown all of our 300
WXP SP2 client PC's in our domain located in the OU: Hosts.
I'v searched through the newsgroups for a complete script but to no result.
Found some interresting scripts but nothing to directly inplement.

Because i can't realy script in VB, i am unable to create my own scripts. I
am able to adjust tho.

I'v found a message here that i would like to edit so it fits our needs.
URL:
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.windows.server.scripting&mid=a836c120-8c3f-41bc-9f16-115bfcd324ba

This message involves the shutdown command. It also suggests to loop through
AD to read the computernames and then execute a remote shutdown with the
resolved computername.
I would realy like to use this but can't script it myself.
I'v also found a script to search trough AD for the computers and added the
script below.

Hope someone can help me with this.
Thx,
Joris

SCRIPT:
-------------------------------------
Public Function AllComputers() As String()

'PURPOSE: Gets all Computers for the current domain
'and returns them in a string array, using LDAP

'Requires: ADSI, LDAP provider
'This function tested on Windows 2000 RC2

'RETURNS: String array containing all
'Computers for the current domain

'Requires VB6 because in lower versions
'array cannot be return type for a
'function

'EXAMPLE
'Dim sArray() As String
'Dim iCtr As Integer

'sArray = AllComputers
'For iCtr = 0 To UBound(sArray)
' Debug.Print sArray(iCtr)
'Next

Dim conn As New ADODB.Connection
Dim rs As ADODB.Recordset
Dim oRoot As IADs
Dim oDomain As IADs
Dim sBase As String
Dim sFilter As String
Dim sDomain As String

Dim sAttribs As String
Dim sDepth As String
Dim sQuery As String
Dim sAns() As String
Dim iElement As Integer

On Error GoTo errhandler:

Set oRoot = GetObject("LDAP://rootDSE";)
sDomain = oRoot.Get("defaultNamingContext")
Set oDomain = GetObject("LDAP://"; & sDomain)
sBase = "<" & oDomain.ADsPath & ">"
sFilter = "(&(objectCategory=Computer))"
sAttribs = "name"
sDepth = "subTree"

sQuery = sBase & ";" & sFilter & ";" & sAttribs & ";" & sDepth

conn.Open _
"Data Source=Active Directory Provider;Provider=ADsDSOObject"

Set rs = conn.Execute(sQuery)
ReDim sAns(0) As String

With rs
Do While Not .EOF
iElement = IIf(sAns(0) = "", 0, iElement + 1)
ReDim Preserve sAns(iElement) As String
sAns(iElement) = rs("name")
.MoveNext
Loop
End With
AllComputers = sAns

errhandler:

On Error Resume Next
If rs.State <> 0 Then rs.Close
If conn.State <> 0 Then conn.Close
Set rs = Nothing
Set conn = Nothing
Set oRoot = Nothing
Set oDomain = Nothing

End Function
.



Relevant Pages

  • Re: Script: Remote shutdown of all domain computers
    ... When trying to run the script from a XP workstation, where i am logged in as ... Dim strBase, strFilter, strAttributes, strQuery, objRecordSet ... 2000 or above and allow shutdown, ... Public Function AllComputersAs String() ...
    (microsoft.public.windows.server.scripting)
  • Re: Script: Remote shutdown of all domain computers in spec. OU
    ... I'v searched through the newsgroups for a complete script but to no ... I'v also found a script to search trough AD for the computers and added ... Public Function AllComputersAs String() ... 'Dim sArray() As String ...
    (microsoft.public.scripting.vbscript)
  • Re: Script: Remote shutdown of all domain computers
    ... Also with this script: What if the IPadress of the PC changed recently? ... 2000 or above and allow shutdown, ... Dim strBase, strFilter, strAttributes, strQuery, objRecordSet ... Public Function AllComputersAs String() ...
    (microsoft.public.windows.server.scripting)
  • Script: Remote shutdown of all domain computers in spec. OU
    ... I'v searched through the newsgroups for a complete script but to no result. ... I'v also found a script to search trough AD for the computers and added the ... Public Function AllComputersAs String() ... 'Dim sArray() As String ...
    (microsoft.public.scripting.vbscript)
  • Re: Script: Remote shutdown of all domain computers
    ... If the computers are Windows ... Dim strBase, strFilter, strAttributes, strQuery, objRecordSet ... Because i can't realy script in VB, i am unable to create my own scripts. ... Public Function AllComputersAs String() ...
    (microsoft.public.windows.server.scripting)