Last active
November 21, 2024 12:32
-
-
Save psitem/dd4a637d9c9449b18230485969ba3091 to your computer and use it in GitHub Desktop.
None of my Windows 2022 Server instances will automatically TRIM my SSD volumes on a schedule, so I wrote this script to run as a scheduled task.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simplified version runs defrag command against all drive letters with only the TRIM flag. Original version | |
# did not run against my Storage Spaces RAID volumes since it couldn't convert a member Physical Disk to a | |
# drive letter but this version does. Drive letters that Windows doesn't recognize as SSD will be skipped. | |
$( Get-Volume | Where-Object { [string] $_.DriveLetter -ne '' } | ForEach-Object { "$($_.DriveLetter):" } ) -join ' ' | ForEach-Object { | |
& defrag $($_ -split ' ') /Retrim /MultiThread | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In retrospect, possibly just running
defrag.exe /Retrim /AllVolumes /MultiThread
would work.