jueves, 14 de agosto de 2014

Batch file to seal Citrix PVS gold server and execute NGEN for sealing gold server

***Save this as main sealing batch

@echo off


rem ***STEP 1: Clear all event logs

wevtutil cl System
wevtutil cl Application
wevtutil cl Security
wevtutil cl Setup


SET /P ANSWER=You want to DELETE profiles (Y/N)?
if /i {%ANSWER%}=={y} (goto :yes)
if /i {%ANSWER%}=={Y} (goto :yes)
goto no
:yes
rem ***STEP 2: Clear user profiles

rem Place a copy of delprof on a shared forlder in the network
rem Link to download delprof tool: 
rem http://www.microsoft.com/en-us/download/details.aspx?id=5405


\\SharedFolder\delprof /p

EVENTCREATE /T Information /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: User Profiles reviewed"

:no
EVENTCREATE /T Information /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: User Profiles deletion skipped"


rem ***STEP 3: Set .NET services to Atumatic(delayed) start

:CALLBATCH
sc config clr_optimization_v4.0.30319_64 start= delayed-auto

if %ERRORLEVEL% == 0 goto SUCCESS1
EVENTCREATE /T ERROR /so CitrixSealing /L Application /ID 2 /D "CitrixSealing: Result for Net optimization x64 service set to delatey-auto: FAILED"
GOTO BREAKEND
:SUCCESS1
EVENTCREATE /T Information /so CitrixSealing /L Application /ID 2 /D "CitrixSealing: Result for Net optimization x64 service set to delatey-auto: SUCCEDED"


sc config clr_optimization_v4.0.30319_32 start= delayed-auto

if %ERRORLEVEL% == 0 goto SUCCESS2
EVENTCREATE /T ERROR /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: Result for Net optimization x86 service set to delatey-auto: FAILED"
GOTO BREAKEND
:SUCCESS2
EVENTCREATE /T Information /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: Result for Net optimization x86 service set to delatey-auto: SUCCEDED"




rem ***STEP 4: Set Windows Automatic Updates service to disable


sc config wuauserv start= disabled

if %ERRORLEVEL% == 0 goto SUCCESS4
EVENTCREATE /T ERROR /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: Result for windows Update Service to Disabled: FAILED"
GOTO BREAKEND
:SUCCESS4
EVENTCREATE /T Information /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: Result for windows Update Service to Disabled: SUCCEDED"




rem ***STEP 5: Run NGEN for both x86 and x84 and log execution results

start \\SharedFolder\NGENx86.bat

if %ERRORLEVEL% == 0 goto SUCCESS5
EVENTCREATE /T ERROR /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: NGEN x86 Process initialization: FAILED"
GOTO BREAKEND
:SUCCESS5
EVENTCREATE /T Information /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: NGEN x86 Process initialization: SUCCEDED"


start \\SharedFolder\NGENx64.bat

if %ERRORLEVEL% == 0 goto SUCCESS6
EVENTCREATE /T ERROR /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: NGEN x64 Process initialization: FAILED"
GOTO BREAKEND
:SUCCESS6
EVENTCREATE /T Information /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: NGEN x64 Process initialization: SUCCEDED"


Echo WARNING (1 of 2): Continue ONLY after BOTH NGEN batch files are completed
Echo WARNING (1 of 2): Continue ONLY after BOTH NGEN batch files are completed
Echo WARNING (1 of 2): Continue ONLY after BOTH NGEN batch files are completed
pause

Echo WARNING (2 of 2): Continue ONLY after BOTH NGEN batch files are completed
pause




rem ***STEP 6: SET .NET Services to disable



sc config clr_optimization_v4.0.30319_64 start= disabled

if %ERRORLEVEL% == 0 goto SUCCESS7
EVENTCREATE /T ERROR /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: Result for Net optimization x86 service set to disabled: FAILED"
GOTO BREAKEND
:SUCCESS7
EVENTCREATE /T Information /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: Result for Net optimization x86 service set to disabled: SUCCEDED"

sc config clr_optimization_v4.0.30319_32 start= disabled

if %ERRORLEVEL% == 0 goto SUCCESS8
EVENTCREATE /T ERROR /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: Result for Net optimization x86 service set to disabled: FAILED"
GOTO BREAKEND
:SUCCESS8
EVENTCREATE /T Information /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: Result for Net optimization x86 service set to disabled: SUCCEDED"



rem ***STEP 7: ipconfig /flushdns


ipconfig /flushdns

if %ERRORLEVEL% == 0 goto SUCCESS9
EVENTCREATE /T ERROR /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: ipconfig /flushdns: FAILED"
GOTO BREAKEND
:SUCCESS9
EVENTCREATE /T Information /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: ipconfig /flushdns occurred"



rem ***STEP 8: Prepare image to seal

cd C:\Program Files (x86)\Citrix\XenApp\ServerConfig\
XenAppConfigConsole.exe /ExecutionMode:ImagePrep /RemoveCurrentServer:False /PrepMsmq:True

if %ERRORLEVEL% == 0 goto SUCCESSa

rem ***STEP X: Break if error found during execution.
:BREAKEND
EVENTCREATE /T ERROR /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: XenAppConfigConsole.exe /ExecutionMode:ImagePrep /RemoveCurrentServer:False /PrepMsmq:True: FAILED"
@ECHO AN ERROR OCCURRED, re run imageprep from XenApp console.
pause


:SUCCESSa
EVENTCREATE /T Information /so CitrixSealing /L Application /ID 1 /D "CitrixSealing: XenAppConfigConsole.exe /ExecutionMode:ImagePrep /RemoveCurrentServer:False /PrepMsmq:True: SUCCEDED"

rem ***STEP 9: Turn off the server

shutdown -s -t 30
cls
@echo Sealing completed, this server now being turned off in 30 secs.
pause
exit

*** end of main Selaing batch

*** start of NGENx64 update

cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319
NGEN update /force
EVENTCREATE /T Warning /L APPLICATION /ID 1 /D "Citrix Sealing: NGEN x64 EXECUTION: END WITH ERRORS"
@ECHO AN ERROR OCCURRED, RE RUN NGEN Update on this server, then continue this batch file execution.
pause
:SUCCESS1
EVENTCREATE /T Information /L APPLICATION /ID 1 /D "Citrix Sealing: NGEN x64 EXECUTION: SUCCEDED"
NGEN eqi
if %ERRORLEVEL% == 0 goto SUCCESS2
EVENTCREATE /T ERROR /L APPLICATION /ID 1 /D "Citrix Sealing: NGEN x64 EQI EXECUTION: END WITH ERRORS"
@ECHO AN ERROR OCCURRED, RE RUN NGEN EQI on this server, then continue this batch file execution.
pause
:SUCCESS2
EVENTCREATE /T Information /L APPLICATION /ID 1 /D "Citrix Sealing: NGEN x64 EQI EXECUTION: SUCCEDED"
cls
@ECHO NGEN completed for x64, you can close this window and go back to main batch file.
pause
exit
***save this as NGENx64.bat and place it on \\sharedfolder
*** end of NGENx64 update

*** start of NGENx86 update
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
NGEN update /force
if %ERRORLEVEL% == 0 goto SUCCESS1
EVENTCREATE /T Warning /L APPLICATION /ID 1 /D "Citrix Sealing: NGEN x86 EXECUTION: END WITH ERRORS"
@ECHO AN ERROR OCCURRED, RE RUN NGEN Update on this server, then continue this batch file execution.
pause
:SUCCESS1
EVENTCREATE /T Information /L APPLICATION /ID 1 /D "Citrix Sealing: NGEN x86 EXECUTION: SUCCEDED"
NGEN eqi
if %ERRORLEVEL% == 0 goto SUCCESS2
EVENTCREATE /T ERROR /L APPLICATION /ID 1 /D "Citrix Sealing: NGEN x86 EQI EXECUTION: END WITH ERRORS"
@ECHO AN ERROR OCCURRED, RE RUN NGEN EQI on this server, then continue this batch file execution.
pause
:SUCCESS2
EVENTCREATE /T Information /L APPLICATION /ID 1 /D "Citrix Sealing: NGEN x86 EQI EXECUTION: SUCCEDED"
cls
@ECHO NGEN completed for x86, you can close this window and go back to main batch file.
pause
exit
***save this as NGENx86.bat and place it on \\sharedfolder
*** end of NGENx86 update

No hay comentarios: