Share via


(solved) How to Trigger Trim in Windows (via powershell, command prompt, Scheduled task)

Question

Thursday, February 7, 2019 5:18 PM

At command prompt or via task, run for example:

Code:

%windir%\system32\defrag.exe /defrag \\?\Volume{9357aabe-3e27-11e4-93c6-806e6f6e6963}\ \\?\Volume{b9b773fd-cfa1-11e8-94a0-021b2b02fe63}\ \\?\Volume{38b9a427-2030-11e9-9ac8-021b2b02fe63}\ \\?\Volume{748e2c57-2036-11e9-92db-021b2b02fe63}\ -o

or

defrag a: c: f: i: -o

The former is microsofts original task directive, for ostensibly to avoid triggering third party defrag software and to survive drive letter changes. For the task directives to survive drive letter changes you will need your drive GUID.

1)

Run, mountvol.exe at command prompt, note EVERY SSD partition GUID. If they are ALL SSD's, then you're in luck, just copy and paste everything.Replace the volume GUID at the top of this page with your own, test at command prompt.

2)

You combine them respectively with a space between

As a scheduled task for example

Code:

%windir%\system32\defrag.exe /defrag \\?\Volume{9357aabe-3e27-11e4-93c6-806e6f6e6963}\ \\?\Volume{b9b773fd-cfa1-11e8-94a0-021b2b02fe63}\ \\?\Volume{38b9a427-2030-11e9-9ac8-021b2b02fe63}\ \\?\Volume{748e2c57-2036-11e9-92db-021b2b02fe63}\ -o

Or simply run

defrag a: c: f: i: -o

WARNING, take note the "-o" at the end of the code, without it you will unnecessarily perform a traditional defrag on your SSD, shortening its lifespan. With -o you will optimize. Run as system or the command prompt will be visible.

Not sure if this is how windows 7 does it also.

This is great for privacy and security; get rid of those pesky bugs & rootkits that write to empty space. (Source? me)

All replies (3)

Thursday, February 7, 2019 5:18 PM âś…Answered

Updated previous post (solved)


Friday, February 8, 2019 2:13 AM | 1 vote

Hi,

Glad to hear that you have found a solution and thank you for sharing it here, it will be helpful to other community members who have same questions.

Regards,

Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Thursday, February 21, 2019 7:54 PM

Updated the batch code, please do check if you are using what was previously posted here, and thank you.