I am writing a script that is going to automate a number of manual steps involved in creating a new image with Citrix PVS.

First step is to copy the most recent base image which is kept in a folder structure. The folder name is always YYYY-MM-DD (description):


I needed to determine the most recent folder and didn’t want to rely on creation date. Instead I walk the directory tree and filter the date out of the filename with a regular expression:


Next step is to copy the base image to the PVS Folder and name it according to the following convention: XenApp5_v{0}_Off2k3_Core where {0} is a 3 digit version number.

So we walk the PVS directory use a regular expression to filter out the version digits. We collect the version digits in an array and use the Measure-Object to obtain the highest number which we then increment by 1:


Last step for this post is to copy the image over to the PVS folder but since the files are large I wanted to have progress indication (which the Copy-Item cmdlet doesn’t have). I found a function that does exactly this on stackoverflow, I only changed [int] to [uint64] to accommodate for files > 2 GB: