Introduction
When publishing an image to PVS the PVS Connector allows for running a PowerShell script after an image is uploaded to the PVS Store and added as a vDisk.
This sample script is intended to show Citrix customers how this scripting can be used to increase administrative productivity.
This script provides a mechanism to modify the vDisk mode to Private, Boot the vDisk on a pre-defined target so that it can run pre-defined layer scripts, the scripts shut down the target, the script waits for that shutdown then switches the mode back to standard.
This script was developed to solve a problem where an Antivirus Process needs to be run against the layered image so that all the files on the image can be excluded from the AV scan. This process did not work as a layer but works well on the layered image. Of course there could be many reasons to use the script from adding applications to licensing.
Limitations
为了使用这个脚本有几个不rtant limitations to be aware of:
- When using a script the image publish tasks will complete before the script has been run. It may be necessary to wait to use a vDisk if the script is still running.
- There are two separate scripts. One to support PVS 7.7 and later and one for earlier versions of PVS 7.x.
Warning
这个示例脚本由Citrix提供解决方案Architects as an example of useful extensions that can be made to Citrix App Layering. These scripts have been tested in our labs but not by our QA department and they are not supported as part of the Citrix App Layering Product. Please test thoroughly and implement with care.
Infrastructure Requirements
The following infrastructure components/configurations are required:
- The script makes extensive use of PVS PowerShell CMDLETS and which must be appropriately initialized.
- PowerShell Execution Policy must be set to remote-signed or unrestricted
- The account defined in the script configuration of the connector must be a local administrator, and PVS administrator and it must have modify rights to the script folder.
Setting Up the Script
- The first step when setting up the script is to create a folder. A folder off the root with no spaces in the name is recommended.
- If the script file is blocked unblock it.
- Unzip into the folder.
- Create a target to use for each image. You want one for each because if you publish images in parallel they may each be running the script at the same time.
- Edit the Image to target lookup file in the config folder named TargetMap.txt. The format is “Image_Name:::Target_Name”.
![file](http://m.giftsix.com/support/files/public/support/article/CTX226062/images/0EM4z000000jrNX.png)
- Edit the PVS connector, click on the Scripts tab and configure the script.
![file](http://m.giftsix.com/support/files/public/support/article/CTX226062/images/0EM4z000000jrNb.png)
Note: If a dash(-) is in the script name the execution will fail.
- In line 23 of the PowerShell script there is a timeout for how long it will wait until the target is shut down. You need to adjust that to be longer than it takes your scripts to run.
![file](http://m.giftsix.com/support/files/public/support/article/CTX226062/images/0EM4z000000jrNY.png)
Layer Scripts
When the image is booted in private mode it will execute any scripts you have pre-defined in layers using the layer script path in the Layering Wizard.
To include a layer script create a cmd file (I usually put them in c:\windows\setup\scripts). In your script you need two things an if statement that will ensure that your script only runs when the image is initially booted and a shutdown command at the end. Of course if you have multiple scripts that you need to run together you wont know the sequence so you must allow enough time in the shutdown command to let the other scripts run or create a layer and put all the scripts together so that you control the order.
In this example script we run two other scripts then the shutdown. Note the use of “call” which ensures that the script waits for the return before it moves on to the next command:
![file](http://m.giftsix.com/support/files/public/support/article/CTX226062/images/0EM4z000000jrNa.png)
The customized script should delete any file that ends in "_done" from the below directories, prior to shutdown.
-C:\Windows\Setup\Scripts\
-C:\Windows\Setup\Scripts\kmsdir
These steps are needed to ensure Office activation works properly.
When you finalize the layer add the path to this cmd file to the script path field in the UI.
![file](http://m.giftsix.com/support/files/public/support/article/CTX226062/images/0EM4z000000jrNZ.png)
So something like c:\windows\setup\scripts\vietool.cmd
It’s a pretty simple the way it works. After the vDisk is published. It calls the PowerShell script and passes the disk locator (PVS term for the id of the disk). The script looks up the disk, captures its writecachetype, changes it to private mode, boots the target defined for that image, then the script in the image is called and it runs the commands you scripted, at the end your script shuts down the machine, meanwhile the PowerShell script is waiting for the target to shut down. When it does it changes the disk mode back to standard and resets the write cache type.
Your script will actually get called every boot but since we created the log file it will never run anything after the initial run..
Test
It is critical to test the script on test vdisks on a test PVSServer. Test all the way to deploying targets using the vDisk that was modified.
The script creates a detailed log for each image. Review the log after each test.