How to execute gpupdate to a range of IPs using DOS Batch File in Windows OS

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Ahmed.Faraz.Hashmi
Posts: 3
Joined: 19 Apr 2017 21:23

How to execute gpupdate to a range of IPs using DOS Batch File in Windows OS

#1 Post by Ahmed.Faraz.Hashmi » 19 Apr 2017 21:36

I want to run "gpupdate/force" command on all network PCs through DOS batch file. Following batch program is just to traverse through a list of IPs saved in a text file. How may I achieve my requirement. Thanks.

Code: Select all

@echo off
cls
setlocal enableextensions enabledelayedexpansion

@echo List of offline PC's > offline_%date%.txt

for /f %%i in (ip_range.txt) do (
   SET bHOSTUP=0
   Echo --------------------------------------   
   ping -n 1 -a %%i |find "TTL=" && SET bHOSTUP=1
   IF !bHOSTUP! equ 1 (
      CALL :HOSTUP %%i
   ) else (
      CALL :HOSTDOWN %%i
   )
)

::----------------------------------
:HOSTUP
echo Host UP %1
GOTO EOF

::----------------------------------

:HOSTDOWN
echo Host DOWN %1
@echo %1 >> offline_%date%.txt
GOTO EOF

::----------------------------------

:EOF

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: How to execute gpupdate to a range of IPs using DOS Batch File in Windows OS

#2 Post by ShadowThief » 20 Apr 2017 05:47

Your code works alright for me, though you might want to stick an exit /b after the last ) and before :HOSTUP just so it doesn't get run at the very end.

What problem are you having?

Ahmed.Faraz.Hashmi
Posts: 3
Joined: 19 Apr 2017 21:23

Re: How to execute gpupdate to a range of IPs using DOS Batch File in Windows OS

#3 Post by Ahmed.Faraz.Hashmi » 23 Apr 2017 23:27

Thanks for your reply but my problem is regarding run some dos command e.g. "gpupdate/force" on an IP within the loop of dos batch file. :?: Is it possible; if yes then how may I update the given code.

Thanks again.

Ahmed.Faraz.Hashmi
Posts: 3
Joined: 19 Apr 2017 21:23

Re: How to execute gpupdate to a range of IPs using DOS Batch File in Windows OS

#4 Post by Ahmed.Faraz.Hashmi » 23 Apr 2017 23:53

ShadowThief wrote:What problem are you having?



I want to run "gpupdate/force" command on all network PCs through DOS batch file. Following batch program is just to traverse through a list of IPs saved in a text file. How may I achieve my requirement. Thanks.

Post Reply