From: magician on
Hey all!

Can anyone help at all? I am doing my head in! Can't quite get the hang of
all this scripting mallarkey.

Here's what I'm currently doing:

I need to shutdown all my PC's overnight. At the moment I have a list taken
from the DHCP scope of all the PC's on the network. I've made that list into
one huge batch file that uses PSShutdown to shutdown/restart EACH address in
the list regardless of whether it is switched on or off. This takes ages (so
we split it between 4 servers and they each do about 500 addresses) :)

Here's what I'm trying to do:

I want to continue using PSShutdown for now. I want to ping all the PC's in
the DHCP scope and create a text file of all those that reply. I then want to
run PSShutdown against the "active" PC's.

I have the first bit sorted and am getting a list of "active" PC's using this:

'--------------------8<----------------------

Const ForReading = 1
Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const OverwriteIfExist = -1

Set objShell = Wscript.CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile("d:\ComputerList.txt", _
ForReading, FailIfNotExist, OpenAsASCII)

Set objOutputFile = objFSO.CreateTextFile _
("d:\PingLog.txt", OverwriteIfExist, OpenAsASCII)

Do Until objFile.AtEndOfStream

strComputer = Trim(objFile.ReadLine)
If strComputer <> "" Then
If IsConnectible(strComputer, 1, "") Then
objOutputFile.WriteLine strComputer
End If
End If
Loop

objFile.Close
objOutputFile.Close


Function IsConnectible(sHost, iPings, iTO)
' Returns True or False based on the output from ping.exe
'
' Author: Alex Angelopoulos/Torgeir Bakken
' Works an "all" WSH versions
' sHost is a hostname or IP
' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used

Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1
Dim oShell, oFSO, sTempFile, fFile

If iPings = "" Then iPings = 2
If iTO = "" Then iTO = 750

Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")

sTempFile = oFSO.GetSpecialFolder(2).ShortPath & "\" & oFSO.GetTempName

oShell.Run "%comspec% /c ping.exe -n " & iPings & " -w " & iTO _
& " " & sHost & ">" & sTempFile, 0 , True

Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
FailIfNotExist, OpenAsASCII)

sResults = fFile.ReadAll
fFile.Close
oFSO.DeleteFile(sTempFile)
IsConnectible = CBool(InStr(sResults, "TTL="))

End Function

'--------------------8<----------------------

(Thanks Torgeir/Alex! :))

I just can't figure out how to get PSShutdown to run against pinglog.txt!

The command line for PSShutdown looks something like this:
psshutdown -f -r -n 3 \\192.168.0.1

At the moment I am trying to do this in a second script. My idea is to call
the second script from the first one. I guess it is better to do it all in
one!? Either way I am completely lost for now.

Any help would be greatly appreciated.

Many tia
Tom
From: Ian on
Hi,
This is the way I found that worked for me.

On Error Resume Next

Dim strFilename
strFilename = "c:\file.txt"

Dim objFSO, objTS, strComputer
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.OpenTextFile(strFilename)
Do Until objTS.AtEndOfStream
strComputer = objTS.ReadLine

strComputer = UCase(strComputer)
Set colItems = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("SELECT * FROM Win32_PingStatus where address = '" & strComputer & "'")
For Each objItem in colItems
if objItem.StatusCode = 0 Then
PC= "ON"
Else
PC = "OFF"
End if
Next
If PC = "ON" then
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objItem in colItems
strdomuser = ""&objItem.UserName
dpos = InStr(strdomuser,"\")
strlen = Len(strdomuser)
strdomuser = Right(strdomuser,strlen-dpos)
strdomuser = UCase(strdomuser)
if strdomuser ="" Then
Set wshshl = WScript.CreateObject("wscript.Shell")
' PSShutdown.exe is available from SYSInternals.com FREE!!!!!
' if you want to close apps remotley use PSKILL.EXE here
strrunme = "cmd /c psshutdown -f -k \\" &strComputer
wshshl.run strrunme,0
end if
Next
End If

Loop
objTS.Close


On Tue, 14 Jun 2005 11:49:01 -0700, "magician" <magician(a)discussions.microsoft.com> wrote:

>Hey all!
>
>Can anyone help at all? I am doing my head in! Can't quite get the hang of
>all this scripting mallarkey.
>
>Here's what I'm currently doing:
>
>I need to shutdown all my PC's overnight. At the moment I have a list taken
>from the DHCP scope of all the PC's on the network. I've made that list into
>one huge batch file that uses PSShutdown to shutdown/restart EACH address in
>the list regardless of whether it is switched on or off. This takes ages (so
>we split it between 4 servers and they each do about 500 addresses) :)
>
>Here's what I'm trying to do:
>
>I want to continue using PSShutdown for now. I want to ping all the PC's in
>the DHCP scope and create a text file of all those that reply. I then want to
>run PSShutdown against the "active" PC's.
>
>I have the first bit sorted and am getting a list of "active" PC's using this:
>
>'--------------------8<----------------------
>
>Const ForReading = 1
>Const OpenAsASCII = 0
>Const FailIfNotExist = 0
>Const OverwriteIfExist = -1
>
>Set objShell = Wscript.CreateObject("Wscript.Shell")
>Set objFSO = CreateObject("Scripting.FileSystemObject")
>
>Set objFile = objFSO.OpenTextFile("d:\ComputerList.txt", _
> ForReading, FailIfNotExist, OpenAsASCII)
>
>Set objOutputFile = objFSO.CreateTextFile _
> ("d:\PingLog.txt", OverwriteIfExist, OpenAsASCII)
>
>Do Until objFile.AtEndOfStream
>
> strComputer = Trim(objFile.ReadLine)
> If strComputer <> "" Then
> If IsConnectible(strComputer, 1, "") Then
> objOutputFile.WriteLine strComputer
> End If
> End If
>Loop
>
>objFile.Close
>objOutputFile.Close
>
>
>Function IsConnectible(sHost, iPings, iTO)
> ' Returns True or False based on the output from ping.exe
> '
> ' Author: Alex Angelopoulos/Torgeir Bakken
> ' Works an "all" WSH versions
> ' sHost is a hostname or IP
> ' iPings is number of ping attempts
> ' iTO is timeout in milliseconds
> ' if values are set to "", then defaults below used
>
> Const OpenAsASCII = 0
> Const FailIfNotExist = 0
> Const ForReading = 1
> Dim oShell, oFSO, sTempFile, fFile
>
> If iPings = "" Then iPings = 2
> If iTO = "" Then iTO = 750
>
> Set oShell = CreateObject("WScript.Shell")
> Set oFSO = CreateObject("Scripting.FileSystemObject")
>
> sTempFile = oFSO.GetSpecialFolder(2).ShortPath & "\" & oFSO.GetTempName
>
> oShell.Run "%comspec% /c ping.exe -n " & iPings & " -w " & iTO _
> & " " & sHost & ">" & sTempFile, 0 , True
>
> Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
> FailIfNotExist, OpenAsASCII)
>
> sResults = fFile.ReadAll
> fFile.Close
> oFSO.DeleteFile(sTempFile)
> IsConnectible = CBool(InStr(sResults, "TTL="))
>
>End Function
>
>'--------------------8<----------------------
>
>(Thanks Torgeir/Alex! :))
>
>I just can't figure out how to get PSShutdown to run against pinglog.txt!
>
>The command line for PSShutdown looks something like this:
>psshutdown -f -r -n 3 \\192.168.0.1
>
>At the moment I am trying to do this in a second script. My idea is to call
>the second script from the first one. I guess it is better to do it all in
>one!? Either way I am completely lost for now.
>
>Any help would be greatly appreciated.
>
>Many tia
>Tom

From: magician on
Ian you are a star! I will test this later but it certainly looks good to me.
And I'd never have figured this lot out :)
Thank you.

"Ian" wrote:

> Hi,
> This is the way I found that worked for me.
>
> On Error Resume Next
>
> Dim strFilename
> strFilename = "c:\file.txt"
>
> Dim objFSO, objTS, strComputer
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTS = objFSO.OpenTextFile(strFilename)
> Do Until objTS.AtEndOfStream
> strComputer = objTS.ReadLine
>
> strComputer = UCase(strComputer)
> Set colItems = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("SELECT * FROM Win32_PingStatus where address = '" & strComputer & "'")
> For Each objItem in colItems
> if objItem.StatusCode = 0 Then
> PC= "ON"
> Else
> PC = "OFF"
> End if
> Next
> If PC = "ON" then
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
> Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
> For Each objItem in colItems
> strdomuser = ""&objItem.UserName
> dpos = InStr(strdomuser,"\")
> strlen = Len(strdomuser)
> strdomuser = Right(strdomuser,strlen-dpos)
> strdomuser = UCase(strdomuser)
> if strdomuser ="" Then
> Set wshshl = WScript.CreateObject("wscript.Shell")
> ' PSShutdown.exe is available from SYSInternals.com FREE!!!!!
> ' if you want to close apps remotley use PSKILL.EXE here
> strrunme = "cmd /c psshutdown -f -k \\" &strComputer
> wshshl.run strrunme,0
> end if
> Next
> End If
>
> Loop
> objTS.Close
>
>
> On Tue, 14 Jun 2005 11:49:01 -0700, "magician" <magician(a)discussions.microsoft.com> wrote:
>
> >Hey all!
> >
> >Can anyone help at all? I am doing my head in! Can't quite get the hang of
> >all this scripting mallarkey.
> >
> >Here's what I'm currently doing:
> >
> >I need to shutdown all my PC's overnight. At the moment I have a list taken
> >from the DHCP scope of all the PC's on the network. I've made that list into
> >one huge batch file that uses PSShutdown to shutdown/restart EACH address in
> >the list regardless of whether it is switched on or off. This takes ages (so
> >we split it between 4 servers and they each do about 500 addresses) :)
> >
> >Here's what I'm trying to do:
> >
> >I want to continue using PSShutdown for now. I want to ping all the PC's in
> >the DHCP scope and create a text file of all those that reply. I then want to
> >run PSShutdown against the "active" PC's.
> >
> >I have the first bit sorted and am getting a list of "active" PC's using this:
> >
> >'--------------------8<----------------------
> >
> >Const ForReading = 1
> >Const OpenAsASCII = 0
> >Const FailIfNotExist = 0
> >Const OverwriteIfExist = -1
> >
> >Set objShell = Wscript.CreateObject("Wscript.Shell")
> >Set objFSO = CreateObject("Scripting.FileSystemObject")
> >
> >Set objFile = objFSO.OpenTextFile("d:\ComputerList.txt", _
> > ForReading, FailIfNotExist, OpenAsASCII)
> >
> >Set objOutputFile = objFSO.CreateTextFile _
> > ("d:\PingLog.txt", OverwriteIfExist, OpenAsASCII)
> >
> >Do Until objFile.AtEndOfStream
> >
> > strComputer = Trim(objFile.ReadLine)
> > If strComputer <> "" Then
> > If IsConnectible(strComputer, 1, "") Then
> > objOutputFile.WriteLine strComputer
> > End If
> > End If
> >Loop
> >
> >objFile.Close
> >objOutputFile.Close
> >
> >
> >Function IsConnectible(sHost, iPings, iTO)
> > ' Returns True or False based on the output from ping.exe
> > '
> > ' Author: Alex Angelopoulos/Torgeir Bakken
> > ' Works an "all" WSH versions
> > ' sHost is a hostname or IP
> > ' iPings is number of ping attempts
> > ' iTO is timeout in milliseconds
> > ' if values are set to "", then defaults below used
> >
> > Const OpenAsASCII = 0
> > Const FailIfNotExist = 0
> > Const ForReading = 1
> > Dim oShell, oFSO, sTempFile, fFile
> >
> > If iPings = "" Then iPings = 2
> > If iTO = "" Then iTO = 750
> >
> > Set oShell = CreateObject("WScript.Shell")
> > Set oFSO = CreateObject("Scripting.FileSystemObject")
> >
> > sTempFile = oFSO.GetSpecialFolder(2).ShortPath & "\" & oFSO.GetTempName
> >
> > oShell.Run "%comspec% /c ping.exe -n " & iPings & " -w " & iTO _
> > & " " & sHost & ">" & sTempFile, 0 , True
> >
> > Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
> > FailIfNotExist, OpenAsASCII)
> >
> > sResults = fFile.ReadAll
> > fFile.Close
> > oFSO.DeleteFile(sTempFile)
> > IsConnectible = CBool(InStr(sResults, "TTL="))
> >
> >End Function
> >
> >'--------------------8<----------------------
> >
> >(Thanks Torgeir/Alex! :))
> >
> >I just can't figure out how to get PSShutdown to run against pinglog.txt!
> >
> >The command line for PSShutdown looks something like this:
> >psshutdown -f -r -n 3 \\192.168.0.1
> >
> >At the moment I am trying to do this in a second script. My idea is to call
> >the second script from the first one. I guess it is better to do it all in
> >one!? Either way I am completely lost for now.
> >
> >Any help would be greatly appreciated.
> >
> >Many tia
> >Tom
>
>
From: magician on
Hi Ian,

Thanks for that. Have had a bit of a test last night and it worked after a
bit of tweaking. I had to remove half of the second "if" though! What exactly
does this bit do?

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
> Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
> For Each objItem in colItems
> strdomuser = ""&objItem.UserName
> dpos = InStr(strdomuser,"\")
> strlen = Len(strdomuser)
> strdomuser = Right(strdomuser,strlen-dpos)
> strdomuser = UCase(strdomuser)
> if strdomuser ="" Then

????
As a rough guess, it's checking who is logged on and the script only shuts
down PC's that are not logged on?

If I leave that bit (and remove pause on error) I get this error:

line 22 char2
permission denied 'GetObject'
800A0046

here:
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Any idea what that's all about??

Cheers
Tom


===============================================

"magician" wrote:

> Ian you are a star! I will test this later but it certainly looks good to me.
> And I'd never have figured this lot out :)
> Thank you.
>
> "Ian" wrote:
>
> > Hi,
> > This is the way I found that worked for me.
> >
> > On Error Resume Next
> >
> > Dim strFilename
> > strFilename = "c:\file.txt"
> >
> > Dim objFSO, objTS, strComputer
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > Set objTS = objFSO.OpenTextFile(strFilename)
> > Do Until objTS.AtEndOfStream
> > strComputer = objTS.ReadLine
> >
> > strComputer = UCase(strComputer)
> > Set colItems = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("SELECT * FROM Win32_PingStatus where address = '" & strComputer & "'")
> > For Each objItem in colItems
> > if objItem.StatusCode = 0 Then
> > PC= "ON"
> > Else
> > PC = "OFF"
> > End if
> > Next
> > If PC = "ON" then
> > Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
> > Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
> > For Each objItem in colItems
> > strdomuser = ""&objItem.UserName
> > dpos = InStr(strdomuser,"\")
> > strlen = Len(strdomuser)
> > strdomuser = Right(strdomuser,strlen-dpos)
> > strdomuser = UCase(strdomuser)
> > if strdomuser ="" Then
> > Set wshshl = WScript.CreateObject("wscript.Shell")
> > ' PSShutdown.exe is available from SYSInternals.com FREE!!!!!
> > ' if you want to close apps remotley use PSKILL.EXE here
> > strrunme = "cmd /c psshutdown -f -k \\" &strComputer
> > wshshl.run strrunme,0
> > end if
> > Next
> > End If
> >
> > Loop
> > objTS.Close
> >
> >
> > On Tue, 14 Jun 2005 11:49:01 -0700, "magician" <magician(a)discussions.microsoft.com> wrote:
> >
> > >Hey all!
> > >
> > >Can anyone help at all? I am doing my head in! Can't quite get the hang of
> > >all this scripting mallarkey.
> > >
> > >Here's what I'm currently doing:
> > >
> > >I need to shutdown all my PC's overnight. At the moment I have a list taken
> > >from the DHCP scope of all the PC's on the network. I've made that list into
> > >one huge batch file that uses PSShutdown to shutdown/restart EACH address in
> > >the list regardless of whether it is switched on or off. This takes ages (so
> > >we split it between 4 servers and they each do about 500 addresses) :)
> > >
> > >Here's what I'm trying to do:
> > >
> > >I want to continue using PSShutdown for now. I want to ping all the PC's in
> > >the DHCP scope and create a text file of all those that reply. I then want to
> > >run PSShutdown against the "active" PC's.
> > >
> > >I have the first bit sorted and am getting a list of "active" PC's using this:
> > >
> > >'--------------------8<----------------------
> > >
> > >Const ForReading = 1
> > >Const OpenAsASCII = 0
> > >Const FailIfNotExist = 0
> > >Const OverwriteIfExist = -1
> > >
> > >Set objShell = Wscript.CreateObject("Wscript.Shell")
> > >Set objFSO = CreateObject("Scripting.FileSystemObject")
> > >
> > >Set objFile = objFSO.OpenTextFile("d:\ComputerList.txt", _
> > > ForReading, FailIfNotExist, OpenAsASCII)
> > >
> > >Set objOutputFile = objFSO.CreateTextFile _
> > > ("d:\PingLog.txt", OverwriteIfExist, OpenAsASCII)
> > >
> > >Do Until objFile.AtEndOfStream
> > >
> > > strComputer = Trim(objFile.ReadLine)
> > > If strComputer <> "" Then
> > > If IsConnectible(strComputer, 1, "") Then
> > > objOutputFile.WriteLine strComputer
> > > End If
> > > End If
> > >Loop
> > >
> > >objFile.Close
> > >objOutputFile.Close
> > >
> > >
> > >Function IsConnectible(sHost, iPings, iTO)
> > > ' Returns True or False based on the output from ping.exe
> > > '
> > > ' Author: Alex Angelopoulos/Torgeir Bakken
> > > ' Works an "all" WSH versions
> > > ' sHost is a hostname or IP
> > > ' iPings is number of ping attempts
> > > ' iTO is timeout in milliseconds
> > > ' if values are set to "", then defaults below used
> > >
> > > Const OpenAsASCII = 0
> > > Const FailIfNotExist = 0
> > > Const ForReading = 1
> > > Dim oShell, oFSO, sTempFile, fFile
> > >
> > > If iPings = "" Then iPings = 2
> > > If iTO = "" Then iTO = 750
> > >
> > > Set oShell = CreateObject("WScript.Shell")
> > > Set oFSO = CreateObject("Scripting.FileSystemObject")
> > >
> > > sTempFile = oFSO.GetSpecialFolder(2).ShortPath & "\" & oFSO.GetTempName
> > >
> > > oShell.Run "%comspec% /c ping.exe -n " & iPings & " -w " & iTO _
> > > & " " & sHost & ">" & sTempFile, 0 , True
> > >
> > > Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
> > > FailIfNotExist, OpenAsASCII)
> > >
> > > sResults = fFile.ReadAll
> > > fFile.Close
> > > oFSO.DeleteFile(sTempFile)
> > > IsConnectible = CBool(InStr(sResults, "TTL="))
> > >
> > >End Function
> > >
> > >'--------------------8<----------------------
> > >
> > >(Thanks Torgeir/Alex! :))
> > >
> > >I just can't figure out how to get PSShutdown to run against pinglog.txt!
> > >
> > >The command line for PSShutdown looks something like this:
> > >psshutdown -f -r -n 3 \\192.168.0.1
> > >
> > >At the moment I am trying to do this in a second script. My idea is to call
> > >the second script from the first one. I guess it is better to do it all in
> > >one!? Either way I am completely lost for now.
> > >
> > >Any help would be greatly appreciated.
> > >
> > >Many tia
> > >Tom
> >
> >
From: Ian on
Tom,
Oh, That was to ensure that no user was left logged on. If they were then skip over it, some people
leave their machines running "batch" jobs or compiling overnight.
This saves a lot of angry developers :-)
If it is not needed cut it out.
Ian
On Thu, 16 Jun 2005 10:36:08 -0700, "magician" <magician(a)discussions.microsoft.com> wrote:

>Hi Ian,
>
>Thanks for that. Have had a bit of a test last night and it worked after a
>bit of tweaking. I had to remove half of the second "if" though! What exactly
>does this bit do?
>
>Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
>> Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
>> For Each objItem in colItems
>> strdomuser = ""&objItem.UserName
>> dpos = InStr(strdomuser,"\")
>> strlen = Len(strdomuser)
>> strdomuser = Right(strdomuser,strlen-dpos)
>> strdomuser = UCase(strdomuser)
>> if strdomuser ="" Then
>
>????
>As a rough guess, it's checking who is logged on and the script only shuts
>down PC's that are not logged on?
>
>If I leave that bit (and remove pause on error) I get this error:
>
>line 22 char2
>permission denied 'GetObject'
>800A0046
>
>here:
>Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
>
>Any idea what that's all about??
>
>Cheers
>Tom
>
>
>===============================================
>
>"magician" wrote:
>
>> Ian you are a star! I will test this later but it certainly looks good to me.
>> And I'd never have figured this lot out :)
>> Thank you.
>>
>> "Ian" wrote:
>>
>> > Hi,
>> > This is the way I found that worked for me.
>> >
>> > On Error Resume Next
>> >
>> > Dim strFilename
>> > strFilename = "c:\file.txt"
>> >
>> > Dim objFSO, objTS, strComputer
>> > Set objFSO = CreateObject("Scripting.FileSystemObject")
>> > Set objTS = objFSO.OpenTextFile(strFilename)
>> > Do Until objTS.AtEndOfStream
>> > strComputer = objTS.ReadLine
>> >
>> > strComputer = UCase(strComputer)
>> > Set colItems = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("SELECT * FROM Win32_PingStatus where address = '" & strComputer & "'")
>> > For Each objItem in colItems
>> > if objItem.StatusCode = 0 Then
>> > PC= "ON"
>> > Else
>> > PC = "OFF"
>> > End if
>> > Next
>> > If PC = "ON" then
>> > Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
>> > Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
>> > For Each objItem in colItems
>> > strdomuser = ""&objItem.UserName
>> > dpos = InStr(strdomuser,"\")
>> > strlen = Len(strdomuser)
>> > strdomuser = Right(strdomuser,strlen-dpos)
>> > strdomuser = UCase(strdomuser)
>> > if strdomuser ="" Then
>> > Set wshshl = WScript.CreateObject("wscript.Shell")
>> > ' PSShutdown.exe is available from SYSInternals.com FREE!!!!!
>> > ' if you want to close apps remotley use PSKILL.EXE here
>> > strrunme = "cmd /c psshutdown -f -k \\" &strComputer
>> > wshshl.run strrunme,0
>> > end if
>> > Next
>> > End If
>> >
>> > Loop
>> > objTS.Close
>> >
>> >
>> > On Tue, 14 Jun 2005 11:49:01 -0700, "magician" <magician(a)discussions.microsoft.com> wrote:
>> >
>> > >Hey all!
>> > >
>> > >Can anyone help at all? I am doing my head in! Can't quite get the hang of
>> > >all this scripting mallarkey.
>> > >
>> > >Here's what I'm currently doing:
>> > >
>> > >I need to shutdown all my PC's overnight. At the moment I have a list taken
>> > >from the DHCP scope of all the PC's on the network. I've made that list into
>> > >one huge batch file that uses PSShutdown to shutdown/restart EACH address in
>> > >the list regardless of whether it is switched on or off. This takes ages (so
>> > >we split it between 4 servers and they each do about 500 addresses) :)
>> > >
>> > >Here's what I'm trying to do:
>> > >
>> > >I want to continue using PSShutdown for now. I want to ping all the PC's in
>> > >the DHCP scope and create a text file of all those that reply. I then want to
>> > >run PSShutdown against the "active" PC's.
>> > >
>> > >I have the first bit sorted and am getting a list of "active" PC's using this:
>> > >
>> > >'--------------------8<----------------------
>> > >
>> > >Const ForReading = 1
>> > >Const OpenAsASCII = 0
>> > >Const FailIfNotExist = 0
>> > >Const OverwriteIfExist = -1
>> > >
>> > >Set objShell = Wscript.CreateObject("Wscript.Shell")
>> > >Set objFSO = CreateObject("Scripting.FileSystemObject")
>> > >
>> > >Set objFile = objFSO.OpenTextFile("d:\ComputerList.txt", _
>> > > ForReading, FailIfNotExist, OpenAsASCII)
>> > >
>> > >Set objOutputFile = objFSO.CreateTextFile _
>> > > ("d:\PingLog.txt", OverwriteIfExist, OpenAsASCII)
>> > >
>> > >Do Until objFile.AtEndOfStream
>> > >
>> > > strComputer = Trim(objFile.ReadLine)
>> > > If strComputer <> "" Then
>> > > If IsConnectible(strComputer, 1, "") Then
>> > > objOutputFile.WriteLine strComputer
>> > > End If
>> > > End If
>> > >Loop
>> > >
>> > >objFile.Close
>> > >objOutputFile.Close
>> > >
>> > >
>> > >Function IsConnectible(sHost, iPings, iTO)
>> > > ' Returns True or False based on the output from ping.exe
>> > > '
>> > > ' Author: Alex Angelopoulos/Torgeir Bakken
>> > > ' Works an "all" WSH versions
>> > > ' sHost is a hostname or IP
>> > > ' iPings is number of ping attempts
>> > > ' iTO is timeout in milliseconds
>> > > ' if values are set to "", then defaults below used
>> > >
>> > > Const OpenAsASCII = 0
>> > > Const FailIfNotExist = 0
>> > > Const ForReading = 1
>> > > Dim oShell, oFSO, sTempFile, fFile
>> > >
>> > > If iPings = "" Then iPings = 2
>> > > If iTO = "" Then iTO = 750
>> > >
>> > > Set oShell = CreateObject("WScript.Shell")
>> > > Set oFSO = CreateObject("Scripting.FileSystemObject")
>> > >
>> > > sTempFile = oFSO.GetSpecialFolder(2).ShortPath & "\" & oFSO.GetTempName
>> > >
>> > > oShell.Run "%comspec% /c ping.exe -n " & iPings & " -w " & iTO _
>> > > & " " & sHost & ">" & sTempFile, 0 , True
>> > >
>> > > Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
>> > > FailIfNotExist, OpenAsASCII)
>> > >
>> > > sResults = fFile.ReadAll
>> > > fFile.Close
>> > > oFSO.DeleteFile(sTempFile)
>> > > IsConnectible = CBool(InStr(sResults, "TTL="))
>> > >
>> > >End Function
>> > >
>> > >'--------------------8<----------------------
>> > >
>> > >(Thanks Torgeir/Alex! :))
>> > >
>> > >I just can't figure out how to get PSShutdown to run against pinglog.txt!
>> > >
>> > >The command line for PSShutdown looks something like this:
>> > >psshutdown -f -r -n 3 \\192.168.0.1
>> > >
>> > >At the moment I am trying to do this in a second script. My idea is to call
>> > >the second script from the first one. I guess it is better to do it all in
>> > >one!? Either way I am completely lost for now.
>> > >
>> > >Any help would be greatly appreciated.
>> > >
>> > >Many tia
>> > >Tom
>> >
>> >