This script can be used to prepare layers right before they are finalised.
To install and configure App Layering 4.x see: https://jgspiers.com/installing-configuring-unidesk-4/
To create and update an OS Layer see: https://jgspiers.com/create-update-os-layer-unidesk-4/
To create and update an Application Layer and create Elastic Layers see: https://jgspiers.com/application-layers-elastic-layering-unidesk-4/
Script author: George Spiers – @JGSpiers
With thanks to Trentent Tye for allowing me to include his Ghost Device removal script.
Tested working on OS version: Windows Server 2016, Windows Server 2012 R2, Windows Server 2008 R2, Windows 10, Windows 7.
Description: This scripts runs a number of tasks to clean out temporary folders, clear out Event Log entries, remove ghost devices from Device Manager, and run NGEN native image regenerations before shutting down the image in preparation for layer finalisation. If running this script on Windows 8.1+ or Windows Server 2012 R2+ there is an extra firewall check that looks to see if any of the firewall profiles are disabled and if so, asks if you want to enable them. When patching within an OS Layer version my patching software requires a number of ports to be open and it is easier just to temporarily disable the firewall until patching is done. The problem was remembering to enable the firewall again!
Note: You should run this script each time you create an OS Layer version, Application Layer/version and Platform Layer/version.
Instructions: You must run this script as an administrator. You must also set the PowerShell Execution Policy to atleast “RemoteSigned” or “Unrestricted”.
Download (click below):
ciprian
August 21, 2017download link it’s not working ..yet
ciprian
August 21, 2017working now.
Rotem Sfarad
August 23, 2017sound very helpful thanks buddy ;).
Nick Panaccio
August 23, 2017Out of curiosity, is there any reason you’re asking for the full path of the script on line 52 instead of using something like the following?
$ScriptPath = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition)
Either way, thank you for this.
George Spiers
August 23, 2017No reason at all! Your suggestion is one less input so I’ll stick it in the script. Thanks
Pingback: App Layering – App Layers, Image Templates, and Publishing – Carl Stalhood
Pingback: Detailed Change Log – Carl Stalhood
Ci
September 14, 2017i ran the script, but sometimes i got error on ngen still ran in background…i have to choose shutdown fro finalized exe provide by unidesk. But i did notice that if i just unidesk exe , my PVS will become non genius
Pingback: App Layering – OS Layer and Platform Layer – Carl Stalhood
R
October 16, 2017Sorry, does anybody else have a problem with the zip not opening ? Says Zip file is invalid
George Spiers
October 16, 2017What program are you using to unzip?
R
October 18, 2017windows 7 also tried 7zip …. both said invalid file …..
George Spiers
October 18, 2017No issue here. Windows 10 using 7zip.
R
October 19, 2017my ver of 7zip was too old , updated 7zip and is working now … Thanks for checking
George Spiers
October 19, 2017Thanks for letting me know the issue!
R
October 19, 2017Have you had any issues with the script removing ALL network adapters?
That happened to me when i ran it finalizing/optimizing a platform layer (xenserver,pvs, xendesktop , vda 7.9 )
Nick Panaccio
October 19, 2017I haven’t noticed it removing all adapters, but I did find that it was removing some ghost devices that I actually needed. I wound up creating a “Lite” version of the script that displayed the ghost devices, but did not actually remove them.
George Spiers
October 19, 2017It should not remove any device other than “Ghost Devices” as Nick mentions. You could disable that part of the script to prevent such behaviour.
RP
October 25, 2017After looking into this again , the network adapter is showing fine when i finalize the platform layer , i can build an image ,publish , networking is fine .
When I add a version to the platform layer , that’s when I lose the network adapter …., network connection folder is emty , device manager still shows the adapter as working ?
Vidit Desai
April 18, 2018Is there a way to set Execution Policy back to “Restricted” prior to the “Shutdown for Finalize” command executes in the script?
George Spiers
April 19, 2018Should be able to set “Set-ExecutionPolicy Restricted” before line 476.
You can also run “PowerShell.exe -ExecutionPolicy Unrestricted C:\AppLayeringImagePrep.ps1” from an elevated CMD or else the run box, which temporarily changed the execution mode to unrestricted just to execute the script.
Vijay
May 21, 2018I ran this script at the plaform layer after i installed the VDA. I noticed that at the end of the script, it automatically shutdown the machine. Do i need to reboot the machine and click Finalize and shutdown at the platform layer again or did the PS script already did it for me. I was n’t sure.
Can you please let em know
Thanks,
Vijay
Nick Panaccio
May 21, 2018No, you don’t have to boot the device back up and Finalize. The last line in the PS script actually calls “C:\’Program Files’\Unidesk\Uniservice\ShutdownForFinalize.cmd”, which is exactly what the desktop shortcut is pointed to. You just need to Finalize the layer from within the ELM console after the VM has completely shut down.
George Spiers
May 21, 2018Nick is correct – thanks Nick.
andrew
May 24, 2018the app layering script is awesome! only change i made was changed the ngen.exe update to ngen.exe executequeditems (we were given that method from a Unidesk tech years ago so goes much quicker…not sure if we’re missing anything going that route)
Also, is it normal for this ps1 script to delete itself after it runs/shuts down? it seems to run successfully and shuts the packaging machine down but when i go back in to use it again if need be, its gone and i have to recopy it again
George Spiers
May 25, 2018Thanks – Yes I set it to do that as I don’t like the script to be left on every layer I create.
You can edit the script and remove the self-deletion piece if you want.
Jonathan Phillippe
July 19, 2018I love this script and have been using it for maybe 6 months. After upgrading to Windows 10 1703.1 the portion of the script at the end that deletes files stopped running. Any ideas?
George Spiers
July 21, 2018If you download the script again the errors will be fixed. Was an issue with deleting files from Recycle Bin on newer W10 OS versions.
Shannon C Meyers
December 7, 2018Love the Script.
rankam77
January 23, 2019Do you have similar script for Windows 10 1803?
George Spiers
January 28, 2019I have used the script against W10 1803 and it works fine.
Anonymous
February 1, 2019Failed to load dependency IpamServer of assembly Microsoft.Windows.ServerManager.Ipam.Plugin, Version=10.0.0.0, Culture=
neutral, PublicKeyToken=31bf3856ad364e35 because of the following error : The system cannot find the file specified. (Ex
ception from HRESULT: 0x80070002)
CJeffers
March 25, 2019I’m using it against W10 1809 LTSC and it’s been working fine.
rankam77
February 1, 2019Can we ignore below error?
Failed to load dependency IpamServer of assembly Microsoft.Windows.ServerManager.Ipam.Plugin, Version=10.0.0.0, Culture=
neutral, PublicKeyToken=31bf3856ad364e35 because of the following error : The system cannot find the file specified. (Ex
ception from HRESULT: 0x80070002)
George Spiers
February 2, 2019Can you ignore it? Yes. That message isn’t caused by the script, but is caused by NGEN which the script is running.
Anwar
May 29, 2019i have around 5 Application Layers ( such as chrome, Firefox, office 365) etc.. do i need run the script each time i create the OS Layer version as well as on Platform Layer and application layers as well? OR only on OS Layer version??
George Spiers
May 29, 2019I suggest running it on every layer.
Anthony Denny
February 3, 2020Would this script cause MCSIO to not work correctly on 1912? I can’t get the mcsdif.vhdx to be created on the MCSWCDisk.
George Spiers
May 10, 2020No there is nothing I am aware that would cause this.
Jonathan Pitre
September 24, 2020@Anthony Denny Were you using a scripted install of the VDA client ? If so I had the same problem. The fix was to change the command line slighly to this instead
‘/noreboot /quiet /enable_remote_assistance /disableexperiencemetrics /virtualmachine /INSTALL_MCSIO_DRIVER /noresume /enable_real_time_transport /enable_hdx_ports /enable_hdx_udp_ports /exclude “User Personalization layer”,”Citrix Files for Outlook”,”Citrix Files for Windows”,”Citrix Supportability Tools”,”Citrix Telemetry Service”,”Citrix Personalization for App-V – VDA” /components vda /mastermcsimage’
Jonathan Phillippe
February 4, 2020I’ve been using your script for over a year with great results. Thanks for your help.
There was some big changes in the Citrix ELM recently and I’m using Version 20.1.0.15 and running the script gives me some different messages than in the past and I wanted to see if it is still good to go. Started getting messages like:
“a Microsoft NGen operation is in progress in the background {0},
a Microsoft NGen operation is needed”
Jonathan Pitre
September 24, 2020Citrix App Layering now recommends using “ngen eqi 3” instead of “ngen update”. Please update the script accordingly. Thanks
https://docs.citrix.com/en-us/citrix-app-layering/4/layer/update-layer.html
Roger
March 24, 2021I’ve been using the script for 2 years but I just updated to the 2102 Release of App Layering and my machines would not shutdown until I change that one line as Jonathan mentioned.
Robert Elsey
October 29, 2021Just curious, why do we use ngen eqi 3 and not ngen eqi 1? As according to MS, if you run a priority 3 – Native images are installed when the native image service detects that the computer is idle. If you run priority 1 – Native images are generated and installed immediately, without waiting for idle time. Wouldn’t running a priority 1 be faster so that your not waiting for the system to be idle? Thanks.
Mike
November 23, 2020Thanks for the great Citrix content. Was curious if you were considering updating this script?
Anonymous
March 4, 2021This is a great script. I have been using it for some time. I am wondering if you might want to add a command to delete the RDS timebomb since I have seen that show up as a reason for issues quite a bit.
Pingback: Citrix App Layering: Part One, the OS Layer – Brandon Mitchell
mw
November 19, 2021Has no one tested on Win Server 2019 still ? codename Redstone
IZFE
January 4, 2022Why does the space in disk goes bigger? Every time I execute the script it gets bigger.
Kevin Phillips
January 12, 2022Get an error when creating the Platform Layer. When it asks you to start the packaging Machine, it wont boot, it just boots the UEFI shell. I am using Server 2022 and Hypervisor 8.2. Has anybody else seen this.k
Travis
March 2, 2022Hey George – any ideas when this will be ready for Windows 11 ENT?
Jacob Mani
August 5, 2024can we use this same script for Platform layer and OS layer sealing also?
George Spiers
August 5, 2024Yes absolutely.