This command listing all volumes.
GWMI -namespace root\cimv2 -class win32_volume | FL -property DeviceID
Output:
DeviceID : \\?\Volume{5ec9533e-e4e5-4d99-b8ea-a72673554361}\
DeviceID : \\?\Volume{c4dc8cf6-0000-0000-0000-100000000000}\
DeviceID : \\?\Volume{e3ce6ce0-0000-0000-0000-100000000000}\
DeviceID : \\?\Volume{0cc402b6-0000-0000-007e-000000000000}\
DeviceID : \\?\Volume{73773d2f-0000-0000-0000-100000000000}\
DeviceID : \\?\Volume{c9f9eccc-0000-0000-0000-100000000000}\
DeviceID : \\?\Volume{2bf2a75a-0000-0000-0000-100000000000}\
I want to run chkdsk all volumes, so I added foreach after the command, but I cannot run chkdsk ?
GWMI -namespace root\cimv2 -class win32_volume | FL -property DeviceID | foreach {Write-Host chkdsk FL -property DeviceID /f}
Output
GWMI -namespace root\cimv2 -class win32_volume | FL -property DeviceID | foreach {Write-Host chkdsk FL -property DeviceID /f}
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
chkdsk FL -property DeviceID /f
What can I do for run chkdsk like this.
chkdsk "\\?\Volume{62f86aa7-0000-0000-0000-100000000000}\" /f
CodePudding user response:
Rather than use ChkDsk use the PowerShell replacement Repair-Volume cmdlet.
$Vols = Get-Volume
"There are $($Vols.Count) volumes to process!"
For ($Cntr = 0 ; $Cntr -lt $Vols.Count; $Cntr ) {
Repair-Volume -ObjectId "$($Vols[$($Cntr)].ObjectId)"
}
Sample Results:
There are 7 volumes to process!
NoErrorsFound
Repair-Volume : Cannot open drive for direct access
Activity ID: {c776ba79-43f4-4dc7-82cd-2f61273ea4e3}
At G:\BEKDocs\Scripts\Misc\Set-RepairVolumeOnAllVolumes.ps1:7 char:2
Repair-Volume -ObjectId "$($Vols[$($Cntr)].ObjectId)"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : NotSpecified: (StorageWMI:ROOT/Microsoft/...age/
MSFT_Volume) [Repair-Volume], CimException
FullyQualifiedErrorId : StorageWMI 43013,Repair-Volume
NoErrorsFound
NoErrorsFound
NoErrorsFound
NoErrorsFound
NoErrorsFound
Here are the volumes on my machine:
PS> $vols
DriveLetter FriendlyName FileSystemType DriveType HealthStatus OperationalStatu
s
----------- ------------ -------------- --------- ------------ ----------------
NTFS Fixed Healthy OK
D Unknown CD-ROM Healthy Unknown
H Misc NTFS Fixed Healthy OK
C NVME NTFS Fixed Healthy OK
NTFS Fixed Healthy OK
ESP FAT32 Fixed Healthy OK
G Data NTFS Fixed Healthy OK
You notice the error in the list that was for the D drive (CD/DVD w/no disc). You can of course add more parameters to the command to suit your needs. You could also trap errors with a Try/Catch block.