Using the "For" command to change settings on a list of servers
I’m still working on this strange issue where a random terminal server with Citrix will suddenly stop working. You can ping the server,telnet to 80,1494,3389 works,browsing to the administrative share works but logging on is a no-no. I have 2 MS hotfixes installed that might help but these fixes also add some "additional features" which is food for another blogpost…
I’m not even sure if the server BSOD’s on me. I have to reset the machine to bring it back to life. Then when I check the eventviewer it says:
Event ID: 6008,
The previous system shutdown at 8:55:53 AM on 11/3/2008 was unexpected.
I did a hard-reset of the server at 11:59AM, but the problems started around 8:55AM!!!
The servers are all configured to auto-reboot in case of system failure (after creating a kernel dump). Maybe if I change this, the system might display on the console what’s going on. I don’t want to change my group-policy so I used the "for" command to change this key on all my servers. This is how I did it:
Create a servers.txt file that contains all the hostnames of the servers you wish to change.
Then use this command to change the registry key:
for /f "tokens=* delims=$" %i in (‘type servers.txt’) do reg add "\\%i\HKLM\System\CurrentControlSet\Control\CrashControl" /v AutoReboot /t REG_DWORD /d 0 /f
(copy paste in notepad without word wrap shows the whole line)
This command goes out and adds, (reg add) (or replaces if it already exists) (=/f), the "AutoReboot" key with a DWORD value of 0 for all the servers placed in servers.txt
You can use the "for" command to free you from a lot of manual labor so go ahead and try it out on a testserver!
If this post helped you out, help me out keeping this site alive and visit some of my sponsors on the left or right.. Thanks..!
TAGS: Howto, for each, command, change, registry
