Optimizes the total file size of provisioned packages on the image by replacing identical files with hard links.
PowerShell · Risk: High · Documentation Verified
Last verified: 2026-10-26
Microsoft Dism reference: Optimizes the total file size of provisioned packages on the image by replacing identical files with hard links. The syntax and selected example below are adapted from the pinned Windows Server 2025 reference. Module availability, target configuration and delegated permissions determine whether it can run in your environment. Documentation and parameter text: Microsoft, CC BY 4.0; formatting adapted by Cmdlet World. No execution testing is claimed.
Use an account with the target resource permissions documented for Optimize-AppXProvisionedPackages. Modifying administrative cmdlets may require elevation or delegated administration. This catalog does not assert that ordinary users can execute the command.
Supported environments
Windows / Dism · Windows Server 2025 documentation; feature/module prerequisites apply
Parameters
-LogLevel
Specifies the maximum output level shown in the logs. The default log level is 3. The accepted values are as follows: - 1 = Errors only - 2 = Errors and warnings - 3 = Errors, warnings, and information - 4 = All of the information listed previously, plus debug output
-LogPath
Specifies the full path and file name to log to. If not set, the default is %WINDIR%\Logs\Dism\dism.log. In Windows PE, the default directory is the RAMDISK scratch space which can be as low as 32 MB. The log file will automatically be archived. The archived log file will be saved with .bak appended to the file name and a new log file will be generated. Each time the log file is archived the .bak file will be overwritten. When using a network share that is not joined to a domain, use the net use command together with domain credentials to set access permissions before you set the log path for the DISM log.
-Online (required)
Do not use. Optimize-AppXProvisionedPackages can't optimize provisioned AppX packages if the image is online.
-Path (required)
Specifies the full path to the root directory of the offline Windows image that you will service. If the directory named Windows is not a subdirectory of the root directory, *WindowsDirectory* must be specified.
-ScratchDirectory
Specifies a temporary directory that will be used when extracting files for use during servicing. The directory must exist locally. If not specified, the \Windows\%Temp% directory will be used, with a subdirectory name of a randomly generated hexadecimal value for each run of DISM. Items in the scratch directory are deleted after each operation. You should not use a network share location as a scratch directory to expand a package (.cab or .msu file) for installation. The directory used for extracting files for temporary usage during servicing should be a local directory.
-SystemDrive
Specifies the path to the location of the BootMgr files. This is necessary only when the BootMgr files are located on a partition other than the one that you are running the command from. Use -SystemDrive to service an installed Windows image from a Windows PE environment.
-WindowsDirectory
Specifies the path to the Windows directory relative to the image path. This cannot be the full path to the Windows directory; it should be a relative path. If not specified, the default is the Windows directory in the root of the offline image directory.
Prerequisites
Windows with the Dism module and the Windows feature or management tools that provide it. Confirm target connectivity and version compatibility using the linked Microsoft reference.
Security considerations
This cmdlet changes system state. Review every target and parameter in the official reference, test outside production, and prepare an appropriate backup or rollback. Do not execute the example automatically.
Examples
Example 1: Optimize provisioned packages in an offline Windows image
This command optimizes the total file size of provisioned packages in the image named *image.wim*. Source: Microsoft, CC BY 4.0; transcript prompt/output removed. This example was not executed.