[Help] Switch off all machines in IP range (scheduled task)

Discussion in 'Scripting' started by sebus, Apr 25, 2018.

  1. sebus

    sebus MDL Guru

    Jul 23, 2008
    6,354
    2,026
    210
    Of course I can do it by filling the name of the machines

    But what I really need is to check that some machines might still be on (they all should be due to policy settings be off or sleeping) & power it off

    Anybody knows a nice script that could do it?

    That one did not work as expected (anybody could correct me - in fact it shutdown the machine I was running it from!):

    Code:
    1..254 | foreach-object { (new-object System.Net.Networkinformation.Ping).Send("10.0.10.$_") } | where-object {$_.Status -eq "success"} | foreach-object { psshutdown -s \\$_ }
    Also checked this, but the output is not easily fed to anything else for processing
     
  2. bear_aussie

    bear_aussie MDL Senior Member

    Jun 8, 2015
    271
    292
    10
    #2 bear_aussie, May 13, 2018
    Last edited: May 13, 2018
    a bit late but...

    shotgun approach I used in my college days on Win2k
    students used to stampede out of the J-block computer lab and leave them all on
    most were pre-atx so you couldn't just hit the power switch and get controlled shutdowns
    got gold stars from hot Asian teachers for doing this for them :kissin:
    Code:
    for /l %%a in (1,1,254) do (
        start "" /b shutdown.exe /m \\192.168.1.%%a /s /t 0 /f
    )
    first versions called shutdown.exe directly which took forever to timeout if the machine was already off
    so in came start /b to just fire-and-forget
    doing this from memory so syntax may be off

    edit - forgot that with at psus then had to go around the lab and hit switches - but everything said "now safe to turn off your computer" by then :D
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. sebus

    sebus MDL Guru

    Jul 23, 2008
    6,354
    2,026
    210
    Well, I have machines in 10.0.10.1-10.0.15.254 range