Jump to content
Welcome to our new Citrix community!
  • 0

Execute Script on VDI after MCS Provisioning completed


Aaron Stovall

Question

*Edit, Just realized I posted this in XenApp and not XenDesktop.  Is there a way to move this post to the proper location?*

 

Hello,

 

I am relatively new to working with MCS and was wondering if there is a way for a VDI to automatically execute a script after the provisioning process has completed.  I found a reference to some Before/After script options via the registry from the following post, but I have not been able to find any documentation or references to how they work exactly. http://discussions.citrix.com/topic/378286-customizing-machine-creation-services/

 

I tested this process out and the scripts do indeed execute, but I can't tell specifically where in the provisioning process they actually execute.  As a quick test, I had them both just echo %ComputerName% to a text file and upon reviewing, it would seem that the scripts executed before the machine was either bound to AD or was assigned it's final hostname.  Both the before and after scripts yield the same results.  

 

I am personally looking to execute a script after the provision process has been completed and the hostname has been set so that I can run a script against it to do some final configurations that I don't want baked into a master image.  Additionally I don't want to trigger these via GPO, SCCM, etc. 

 

Has anyone done something similar to this?  Am I going about this all wrong?

 

Thanks

 

Aaron

Link to comment

2 answers to this question

Recommended Posts

  • 1

I just asked this exact question of my TRM and was told this:

 

The custom steps are defined by multi-string values called “Before” (executed before any of the standard steps like Office rearm, DCHP enabling etc.) and/or “After” (after everything but OS rearm and PvD inventory which have to be the last things done to the image) in registry key HKLM\Software\Citrix\MachineIdentityServiceAgent\ImagePreparation, each string in the multi-string being the path to an executable file which is run if it is present.  The files are executed in the order in which they are found in the multi-string.

  • Like 1
Link to comment
  • 0
On 6/20/2017 at 10:18 AM, Johan Greefkes1709152787 said:

I just asked this exact question of my TRM and was told this:

 

The custom steps are defined by multi-string values called “Before” (executed before any of the standard steps like Office rearm, DCHP enabling etc.) and/or “After” (after everything but OS rearm and PvD inventory which have to be the last things done to the image) in registry key HKLM\Software\Citrix\MachineIdentityServiceAgent\ImagePreparation, each string in the multi-string being the path to an executable file which is run if it is present.  The files are executed in the order in which they are found in the multi-string.

 

In addition, would recommend setting the DWORD registry value HKLM\Software\Citrix\MachineIdentityServiceAgent\LOGGING to 1; Log file saved to c:\image-prep.log

 

This helps with the task return status; we use After prep stage to reregister CarbonBlack sensor and Image Optimization using Citrix Optimizer and VMware-OS-Optimization-Tools.

 

 

c:\image-prep.log 

------------Thursday, February 18, 2021 5:58:13 AM---------------
Started Image Prep, arg count 20
Read arguments, OS Rearm False, Office Rearm False, Third Party True, RequirePvd False, RequireWbc True, BuildPvd False, EnableDHCP True, AppScanning False, AppScanResultsFilePath 
Reporting status to 'C:\Program Files\Citrix\PvsVm\Service\PersistedData\PreparationStatus.xml'.
No prior existence of status file detected. Clean prep execution.
WMI ready.
Third party actions found
ThirdParty action C:\****\Scripts\ImagePrep-PreTasks.cmd
ThirdParty action C:\****\Scripts\ImagePrep-PreTasks.cmd, found, executing
ThirdParty action C:\****\Scripts\ImagePrep-PreTasks.cmd, completed, exit code 1
Enabling DHCP on all network adapters
Netsh tool completed, exit code 0
Netsh executed command 'int ipv6 show addresses' successfully 
ReadIpv6Addresses: Found 0 addresses.
EnableDHCP: Checking adapter, vmxnet3 Ethernet Adapter
EnableDHCP: Checking configuration, vmxnet3 Ethernet Adapter
DHCP already enabled for vmxnet3 Ethernet Adapter, nothing to do
Netsh tool completed, exit code 1
DUID = 00-01-00-01-26-24-32-50-00-50-56-ac-c5-68
status = 0
Found 17 interfaces
FreeMibTable status = 1
No inactive interfaces : assume nothing to do
No interesting disabled network interfaces found
The MSMQ service is not installed
Third party actions found
ThirdParty action C:\****\Scripts\ImagePrep-PostTasks.cmd
ThirdParty action C:\****\Scripts\ImagePrep-PostTasks.cmd, found, executing
ThirdParty action C:\****\Scripts\ImagePrep-PostTasks.cmd, completed, exit code 0
ProgramData location is 'C:\ProgramData'
Temp location is 'C:\ProgramData\Citrix\ImagePreparation'
Closing Status file
Completed image preparation

C:\****\Scripts\ImagePrep-PostTasks.cmd

date /t >> C:\temp\ImagePrep-PostTasks.txt
C:\****\Packages\Image-Optimizations\Windows_10_VDI_Optimize-master\1909\LGPO\LGPO.exe /g C:\****\Packages\Image-Optimizations\Windows_10_VDI_Optimize-master\1909\LGPO /v >> C:\temp\ImagePrep-PostTasks.txt 2>> C:\temp\ImagePrep-PostTasks.txt.err
C:\****\Packages\Image-Optimizations\VMware-OS_OptimizationTool\VMwareOSOptimizationTool.exe -o all -t "C:\****\Packages\Image-Optimizations\VMware-OS_OptimizationTool\927301.xml" -v >> C:\temp\ImagePrep-PostTasks.txt 2>> C:\temp\ImagePrep-PostTasks.txt.err
"c:\Program Files\Confer\RepCLI.exe" reregister onrestart >> C:\temp\ImagePrep-PostTasks.txt 2>> C:\temp\ImagePrep-PostTasks.txt.err
date /t >> C:\temp\ImagePrep-PostTasks.txt

Note on CarbonBlack registration, I have seen it fail/timeout if this task gets executed before the CB services start, so if you plan on calling just CB registration, I would recommend adding a short wait.

 

As a best practice, always update test catalog to validate the task log before rolling the update to production. 

 

 

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...