Is there a way to toggle the Windows "compress this drive" command through a command prompt?

Yes, its called the "compact" command.

Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Windows\system32>compact /?

Displays or alters the compression of files on NTFS partitions.

COMPACT [/C | /U] [/S[:dir]] [/A] [/I] [/F] [/Q] [filename [...]]

/C Compresses the specified files. Directories will be marked so that files added afterward will be compressed.

/U Uncompresses the specified files. Directories will be marked so that files added afterward will not be compressed.

/S Performs the specified operation on files in the given directory and all subdirectories. Default "dir" is the current directory.

/A Displays files with the hidden or system attributes. These files are omitted by default.

/I Continues performing the specified operation even after errors have occurred. By default, COMPACT stops when an error is encountered.

/F Forces the compress operation on all specified files, even those which are already compressed. Already-compressed files are skipped by default. /Q Reports only the most essential information. filename Specifies a pattern, file, or directory.

Used without parameters, COMPACT displays the compression state of the current directory and any files it contains. You may use multiple filenames and wildcards. You must put spaces between multiple parameters.

More information here


While the above answer is correct for dealing with an already existing drive it is useful to do this when spinning up a new drive (such as a RAM Drive) at creation time.

This can be done in Windows by appending the /c argument to the format command.

From the documentation:

/c NTFS only. Files created on the new volume will be compressed by default.