Command Line Options

The following table lists the available command line options for CompactVHD.

Option Description
/AcceptEULA Required parameter (if not supplied, the program will tell you where the EULA is and suggest you read it)
/LogName <dir> Overrides the default logfile (not generally needed). The default path is %temp% for the account running the tool.
/LogLevel info Overrides the default logging level. For this program, "info" is recommended.
/VHDFile <path> Fully-qualified path to a single VHDX file. Only this one file will be compacted. Note that you must specify either /VHDFile or /VHDDir but not both.
/VHDDir <dir> Specifies the directory that contains all VHDX files, typically something like “\\server\share”. All VHDs in that directory (except parent/child disks) will be compacted. Note that you must specify either /VHDFile or /VHDDir but not both.
/StartsWith A-L Gives one or more ranges that the file must start with, such as “/StartsWith A-C”. Note that it is actually looking at the part of the path beyond the /VHDDir, so whatever letters come next (typically the username) are what it is looking at.
/WorkDir <dir> Provides a work directory, ideally on local SSD storage. All files for each VHD being compacted will be put in subdirectories of this directory. If a compaction completes successfully, the subdirectory will be deleted. If a compaction fails for some reason, the subdirectory (which also contains VHD log files that might be useful for problem diagnosis) will remain.
The default is %temp%\CompactVHD.
/EraseBK <dir> The program renames the old VHDX files as “.vhd.BK” or “.vhdx.BK”, but that leads to large amounts of space being taken up by the backup files. Running the compactor with /EraseBK will delete those backup (BK) files. Deletion jobs must be run separately after respective compact jobs have completed.
/EraseBKInline Use this backup erase option to automatically delete backup disks created after each compact job has completed.
/ConvertTo <VHD|VHDX> Converts VHD files to VHDX files (or vice versa). Must be used with /VHDDir or /VHDFile.
/SMTPServer <SMTP Server> The program can send an email with a summary of what it did. This specifies the SMTP server to use for sending that email.
/SMTPPort <num> Specifies the SMTPPort to use for sending the summary email. This is generally not needed unless the SMTP server is running on a non-standard port. The default port is 25.
/SMTPSSL Use this option to establish an SSL connection with the SMTP server for sending emails. Some SMTP servers require SSL while others prohibit it.
/SMTPUser <domain\user> UserID for SMTP server. Note that some servers require this to match the /MailFrom address.
/SMTPPass <password> Password for the /SMTPUser. This is assumed to be cleartext, but if you want to provide an encrypted password, prefix the password with "ENCRYPTED:"
/SetSMTPPass <password> Takes the given cleartext password, encrypts it, adds an "ENCRYPTED:" prefix, and writes it into the app.config.
/MailTo <email1[, email2, …] > One or more (comma-separated) email addresses that the summary should be sent to.
/MailFrom <from email> The email address that the summary email will appear to have come from.
/MaxThreads <num> The maximum number of simultaneous compactions. This number might be reduced, based on available space on the /WorkDir drive. Note that the process is heavily I/O-bound, and testing seems to show that running 2 or more simultaneous compactions actually slows it down overall rather than speeding it up. As a result, the default is "1", and use of this option is discouraged.
/MinDiskMB <num> Specifies a minimum disk size in MB before processing. Any VHDX files below this size will be skipped. The default is 500 MB. A less aggressive suggestion is 1024.
/MinSaveMB <num> Specifies the minimum savings in MB required to be worth performing a compaction. The default is zero, but that can result in the creation of a .BK file of many gigabytes just to save a few megabytes. By setting this parameter, you can tell it to skip the compaction and the creation of the .BK file if the savings are minimal.
/MaxHours <num> Stops the process shortly after X hours. It is recommended that if you want to schedule a job to run for 8 hours, set this parameter to 7 hours so that the program will stop cleanly instead of getting interrupted. You can use fractional hours (e.g. "/MaxHours 0.25" = 15 mins). The default is 0, which means "no limit".
/BackupPath <dir> By default, the program will save the user's original files as “.vhd.BK” or “.vhdx.BK” files in the same directory. In case the process is interrupted, and you need to restore them, rename them without the BK extension. The backup location will only keep the most recent backup each time the job is run.
However, keeping backup files in the same directory means that disk space consumed on the disk containing the VHDX will go UP, not down, because the disk contains both the current VHD and the backup VHD. Disk space can be reclaimed when files are erased with the "/EraseBK" option (which you should not do until you are comfortable that there are no issues).
With the /BackupPath option, you can specify an alternate location to store the backup files (perhaps on less expensive disks), so that the disk space consumed on the main drive goes down. Of course, this means that restoring the data will involve copying the files back, rather than just renaming them. The "/EraseBK" option will use the /BackupPath, if specified, as the location in which backup files should be erased.
/MinDaysSinceLastCompaction <num> By default, all VHDX files will be compacted (subject to /MinDiskMB and /MaxHours). Compacting all files might be overkill if the disk was just compacted a few days ago. With this option, you can tell it to skip any VHDX files that were last compacted less than X days ago. The default is 0, which means "no limit".
When set to 30 and running the job weekly, disks that were compacted in the last 30 days will be skipped while focusing on disks that might have not been compacted on the last run if time for the job ran out. This ensures all disks are getting compacted on a regular basis.
/IgnoreFailedParentChecks Overrides the process that checks to see if a child disk exists. Normally, the existence of a child disk would stop the disk compaction process. In the event the CompactVHD tool fails to compact a disk because it cannot safely find VHDX child disks, you can now override this check. Note that any connection between a child and parent disk will be broken after the parent disk has been compacted.
Do NOT use this option with ProfileUnity multi-session or FSLogix multi-session VHDXs.