GET-IT: TEAMS DAY | 1-Day Free Virtual Conference all about Teams. Here on Petri.com - 8/12/20 GET-IT: TEAMS DAY - 8/12/20

Hostname if statements

Home Forums Scripting DOS Command Shell Hostname if statements

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    ]SK[
    Member
    #155180

    Hi all,

    I need to make a batch file that is used to shutdown multiple computers on a network. The below was taken from an article on this site and does work, however I am being told that we need to avoid shutting down certain machines. What I was hoping for was the ability to create some sort of IF/ELSE to do this. The commands are…

    FOR /L %a in (1,1,254) DO shutdown /s /t 120 /m 10.245.212.%a
    FOR /L %b in (1,1,254) DO shutdown /s /t 120 /m 10.245.213.%b
    FOR /L %c in (1,1,254) DO shutdown /s /t 120 /m 10.245.214.%c
    FOR /L %d in (1,1,254) DO shutdown /s /t 120 /m 10.245.215.%d[/CODE]

    What I guess is needed is something like…

    [CODE]FOR /L %a in (1,1,254) DO nslookup 10.245.212.%a (somehow save the output and save it the address as %host)
    If %host = dt-name-00001 or dt-name-00002 or dt-name-00003
    goto end
    else
    shutdown /s /t 120[/CODE]

    Could someone help me with this?[CODE]FOR /L %a in (1,1,254) DO shutdown /s /t 120 /m 10.245.212.%a
    FOR /L %b in (1,1,254) DO shutdown /s /t 120 /m 10.245.213.%b
    FOR /L %c in (1,1,254) DO shutdown /s /t 120 /m 10.245.214.%c
    FOR /L %d in (1,1,254) DO shutdown /s /t 120 /m 10.245.215.%d[/CODE]

    What I guess is needed is something like…

    FOR /L %a in (1,1,254) DO nslookup 10.245.212.%a (somehow save the output and save it the address as %host)
    If %host = dt-name-00001 or dt-name-00002 or dt-name-00003
    goto end
    else
    shutdown /s /t 120[/CODE]

    Could someone help me with this?[CODE]FOR /L %a in (1,1,254) DO nslookup 10.245.212.%a (somehow save the output and save it the address as %host)
    If %host = dt-name-00001 or dt-name-00002 or dt-name-00003
    goto end
    else
    shutdown /s /t 120[/CODE]

    Could someone help me with this?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.