Additional Tasks for the Citrix Servers in the Farm

Here are the additional tasks that I would like to do from the request I had few days ago

To check those entire Citrix servers in the farm, I would like to use a batch scripts file to get the information I need. I will use the same batch scripts syntax that I used to check OS version of our Windows servers last time.

1) Check the registry keys on the entire Citrix servers in the farm

(I assume there is a Ctxsvrlist.txt contains all the Citrix Server list to call in from the same directory where the batch scripts file runs and it will save CTXIMAresult.txt into the directoy as well)


REM Query IMA key on Citirix servers
@echo Off
pushd %~dp0
for /f %%a in (c:\Citrixservers.txt) do (
                Echo Citrix Host %%a is checked
                reg query “\\%%a\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Citrix\IMA\Restart Options\Schedule”
                Echo.
)  >> c:\IMA check Result.txt

2) If there is any discrepancy, create a scheduled task for manually rebooting servers once via GUI version.

To add a schedule task, I prefer to use GUI version since it is easy.

1. Start>Run>taskschd.msc to open Task Scheduler

2. Create a new task

3. Type Name of the task as “Reboot Once”

4. Change User to “system” account with checked “Run whether user is logged on or not ” option

5. Check “Run with Highest Privileges” option

6. Check “Hidden” and Configure for Windows 7, Windows Server 2008 R2

 

7. Go to Trigger tab and Set Date and Time with One time Option

8. Go to Action Tab, and Fill in Program/Script as below image with arguments (/r -reboot,  /t 0 – time to wait 0 sec) and complete task.

 

 

Or, I can still use this command line to perform the same task.

schtasks /create /s Ctxsvr1 /tn “Reboot Once” /sc Once /st 02:00:00 /sd 10/03/2012 /rl highest /tr “Shutdown /r /t 0” /ru “system”

More details to use “Schtasks”, please check Here

3)Set up a task schedule onto remote Citrix servers simultaneously with Command line batch scripts.

I will use “Schtasks /create ” command to make a batch scripts file to add the scheduled tasks onto those Citrix Servers with a discrepancy. Also, I will use the same syntax and same directory conditions above.


REM Create Scheduled task to reboot the Citrix hosts once manually
@echo off
pushd %~dp0
for /f %%a in (c:\CTXrebootlist.txt) do (
                Echo Citrix Host %%a is completed
                schtasks /create /s %%a /tn “Reboot Once” /sc Once /st 05:00:00 /sd 10/04/2012 /rl highest /tr “Shutdown /r /t 0” /ru “system”
) >> c:\CTX_Reboot_Set_complete.txt

4) Remove the scheduled task after the issue is resolved remotely. If the citrix server name is Ctxsvr1, you can use schtasks /remove command to run as following

schtasks /delete /s Ctxsvr1 /tn “Reboot Once” /f

5) Remove the scheduled tasks from all Citrix servers.

REM Remove scheduled task
@echo off
pushd %~dp0
for /f %%a in (c:\CTXrebootlist.txt) do (
        Echo Citrix Host %%a is completed
        schtasks /delete /s %%a /tn “Reboot Once” /f
) >> c:\CTX_Remove_completed.txt