I'm currently listing all the lists of drives in my computer. However, I want to skip the C:\ drive from the output:
This is my code:
# Iterates over all drives found
$SortedDrives = $Drives | Sort-Object -Property Used -Descending
foreach ($Drive in $SortedDrives) {
if ($Drive.Name -eq "C") {
continue
}
Write-Output $Drive.Root
$newSortedDrives = $newSortedDrives += $Drive.Root
}
And this is the output:
Name Used (GB) Free (GB) Provider Root --------- --------- -------- ---- ---------------
C 150.62 688.78 FileSystem C:\
I 2.42 65.94 FileSystem I:\
F 0.09 2.96 FileSystem F:\
G 0.05 16.43 FileSystem G:\
D 0.05 15.67 FileSystem D:\
H 0.03 9.73 FileSystem H:\
Ideally, I want the C drive to be skipped and only display drives I F G D H.
What am I doing wrong? It looks like this instruction:
if ($Drive.Name -eq "C") {
continue
}
Is not doing what it's supposed to do.