Updated November 2024 - The Hyper-V version of ShrinkVHD is here
The new version of ShrinkVHD uses the built in Powershell Storage Module.
ShrinkVHD is a Powershell script that can compact a single FSLogix Profile Container (VHD / VHDX), or multiple Profile Containers via a primary script that calls ShrinkVHD.
Problem:
- After updating redirections.xml with additional exclude rules, existing FSLogix Profile Containers do not remove pre-existing content.
FSLogix FAQ - FSLogix | Container size
- FSLogix Profile Containers can grow and take up too much space on shared storage
Requirements:
frx.exe is required to migrate the existing VHD / VHDX file to an optimised VHD / VHDX file. Copy C:\Program Files\FSLogix\Apps\frx.exe from a computer with the FSLogix Agent installed to C:\Program Files\FSLogix\Apps\frx.exe on the computer running ShrinkVHD.
Full Control permissions to the SMB fileshare hosting FSLogix Profile Containers.
Command Line :
.\shrinkVHD5.ps1 $EXCPath $VHDPath $Backup
# $EXCPath - UNC Path to redirections.xml - e.g. "\\server\share\redirections.xml" - This can be your standard redirections.xml or any well formed xml file specifically for shrinking with additional folders
# $VHDPath - UNC Path to the user's VHD to be shrunk - "\\server\share\user1.domain\user1.domain.vhdx"
# $Backup - Optionally Backup original VHD before making changes - e.g. "Y" - The original VHD will be renamed and retained and a new optimised VHD will be created
E.g.
.\shrinkVHD5.ps1 "\\server\share\redirections.xml" "\\server\share\user1.domain\user1.domain.vhdx" "Y"
Actions :
ShrinkVHD will:
- Check that C:\Program Files\FSLogix\Apps\frx.exe is available
- Check that the VHD(X) file is accessible
- Check that the redirections.xml file is accessible
- Backup the NTFS ACL on the VHD / VHDX file
- Backup the VHD(X) file if specified
- Mount the existing VHD(X) file
- Check the health of the VHD(X) file and repair if necessary
- Read the excludes from the specified redirections.xml file and remove the excluded folders from the VHD(X) file
- Dismount the VHD(X) file
- Use frx.exe to create a new VHD(X) file (removing any unused blocks) shrinking the VHD(X) file
- Restore the NTFS ACL on the VHD(X) file
- Rename the new VHD(X) file back to it's original name ready for use
- Provide a summary of the reclaimed space, and log statistics to .\FSL-Shrink-<date>.log
Note:
ShrinkVHD will not delete AppData\Roaming, AppData\Local, AppData\LocalLow
You do not have to use your production redirections.xml file. You can create a dedicated redirections.xml file for shrinking maintenance.
ShrinkVHD will only read the excludes in the redirections.xml file, therefore if you have any includes that are subfolders of the excluded folder, you should remove the parent exclude from the redirections.xml file and add excludes for the subfolders which you wish to remove.
When the new VHD / VHDX file is created, legacy symbolic links are not created. This should only affect legacy applications.
Symbolics links can be recreated if necessary by running the following commands as the interactive user.
mklink /J "Application Data" "%USERPROFILE%\AppData\Roaming"
mklink /J "Cookies" "%USERPROFILE%\AppData\Local\Microsoft\Windows\INetCookies"
mklink /J "Local Settings" "%USERPROFILE%\AppData\Local"
mklink /J "My Documents" "%USERPROFILE%\Documents"
mklink /J "NetHood" "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Network Shortcuts"
mklink /J "PrintHood" "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Printer Shortcuts"
mklink /J "Recent" "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Recent"
mklink /J "SendTo" "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\SendTo"
mklink /J "Start Menu" "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu"
mklink /J "Templates" "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Templates"
Shrink multiple VHD(X) files:
Modify the $VHDPATH and $XML variables, then run the following command to shrink all VHD(X) files on an FSLogix share
$VHDPath="\\server\share"
$XML="\\server\share\redirections_clean.xml"
$VHDs=Get-ChildItem -Path $VHDPath -Filter *.vhdx -Recurse
foreach ($VHD in $VHDs) {.\ShrinkVHD5.ps1 $XML $VHD.fullname}
Before shrinking all VHD(X) files, shrink the largest VHD(X) file to determine the maximum shrink time. Multiply the max shrink time by the number of VHD(X) files to determine how long the task will take to shrink all VHD(X) files.
It is not recommended to retain backups of VHD(X) files when shrinking multiple containers due to disk space limitations.
The FSL-Shrink-<date>.log file will log size statistics for each shrink operation.
If a VHD(X) file is in use, it will not be modified. "InUse" will be logged.
Related Articles :
Frx.exe migrated-vhd
|