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.
- After updating redirections.xml with additional exclude rules, existing FSLogix Profile Containers do not remove pre-existing content.
- FSLogix Profile Containers can grow and take up too much space on shared storage
The machine running ShrinkVHD must have the Hyper-V role and Hyper-V Powershell feature installed to mount FSLogix Profile Containers (VHD / VHDX files) hosted on SMB storage.
The FSLogix Agent must be installed as frx.exe is required to migrate the existing VHD / VHDX file to an optimised VHD / VHDX file.
Full Control permissions to the SMB fileshare hosting FSLogix Profile Containers.
Command Line :
.\shrinkVHD4.ps1 $FSPath $MapLetter $Mapuser $pwd $EXCPath $VHDPath $Backup
# $FSPath - UNC path to the root of the SMB FSLogix Share - e.g. "\\server\share" - This is mapped using.........
# $MapLetter - Drive letter to map to the FS Logix share - e.g. "Z"
# $Mapuser - Username to map the FSLogix Share - e.g. "DOMAIN\FSAdmin"
# $pwd - Cleartext password of the $Mapuser - e.g. "FSP@55w0rd"
# $EXCPath - Relative Path to redirections.xml using the $MapLetter - e.g. "Z:\redirections.xml" - This can be your standard redirections.xml or any well formed xml file specifically for shrinking with additional folders - e.g. "Z:\shrink.xml"
# $VHDPath - Relative Path to the user's VHD to be shrunk using the $MapLetter - e.g. "Z:\user1.domain\user1.domain.vhdx"
# $Backup - Backup original VHD before making changes - e.g. "Y" (optional)
.\shrinkVHD4.ps1 "\\server\share" "Z" "DOMAIN\FSAdmin" "FSP@55w0rd" "Z:\redirections.xml" "Z:\user1.domain\user1.domain.vhd" "Y"
- Map a drive to the FSLogix Profile Share using the specified credentials
- Validate that the specified VHD / VHDX file is not in use
- Optionally backup the existing VHD / VHDX
- Backup the NTFS ACL on the VHD / VHDX file
- Mount the existing VHD / VHDX file
- Read the excludes from the specified redirections.xml file and remove the excluded folders from the VHD / VHDX
- Dismount the VHD / VHDX
- Use frx.exe to create a new VHD / VHDX file (removing any unused blocks) shrinking the VHD / VHDX
- Restore the NTFS ACL on the VHD / VHDX file
- Rename the new VHD / VHDX file back to it's original name ready for use
- Provide a summary of the reclaimed space.
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"
Related Articles :