Script: Remote shutdown of all domain computers in spec. OU
- From: Joris van der Struijk <JorisvanderStruijk@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 27 Mar 2006 06:12:02 -0800
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'm no expert VB, i am unable to create my own script. I however
know enough to adjust a little bit.
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 known 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
.
- Follow-Ups:
- Re: Script: Remote shutdown of all domain computers in spec. OU
- From: Filip Nespor
- Re: Script: Remote shutdown of all domain computers in spec. OU
- From: FootBallUBet
- Re: Script: Remote shutdown of all domain computers in spec. OU
- Prev by Date: Re: Script to delete files by size???????
- Next by Date: random unique code
- Previous by thread: Re: Script to delete files by size???????
- Next by thread: Re: Script: Remote shutdown of all domain computers in spec. OU
- Index(es):
Relevant Pages
|
Loading