we needed some help. in practice we were looking for a method to start the defremmentation (defrag) of the primary disk (on windows "C:") only if it is a HDD and not an SSD we read about the command in powershell but can't compile (mediaType)
Asked
Active
Viewed 126 times
0
-
Does this answer your question? [Powershell: How to combine the output of 2 commands to associate disk letter with disk MediaType?](https://stackoverflow.com/questions/68883482/powershell-how-to-combine-the-output-of-2-commands-to-associate-disk-letter-wit) – Doug Maurer Nov 15 '21 at 21:41
-
windows does automatic defragmentation when it needs doing. so ... why are you wanting to override the standard behavior? – Lee_Dailey Nov 16 '21 at 00:36
1 Answers
0
This script should work for you:
#Get friendly name of the C drive
$name = (get-partition -DriveLetter C | get-disk).FriendlyName
#Use friendly name to determine drive type
$mediatype = (Get-PhysicalDisk -FriendlyName $name).MediaType
#Defragment drive if drive type is HDD
if ($mediatype -eq "HDD")
{
Optimize-Volume -DriveLetter C
}

Coolcreeper
- 134
- 9