Fix your disk using the PowerShell successor to chkdsk, Repair-Volume.
Fixing a corrupted file system, the old way
At some point in your IT career, you’ve likely encountered a few bad sectors on a hard drive. The impact can be anything from stuttering performance to a non-starting computer.
Since 1981, chkdsk has been the go-to built-in Microsoft utility for scanning and fixing the disk. By “fixing” I don’t mean it can physically repair the disk itself, but checking the file system integrity and fix any logical file system errors.
While chkdsk is still available in Windows today, a successor PowerShell cmdlet was introduced in Windows Server 2012, Repair-Volume.
Repair-Volume
As the cmdlet name implies, Repair-Volume performs repairs on a volume. It comes with parameters to match up with existing chkdsk capabilities. NOTE: Repair-Volume must be ran from an elevated (aka Administrator) session.
SYNTAX
Repair-Volume [-DriveLetter] <Char[]> [-CimSession <CimSession[]>] [-OfflineScanAndFix] [-Scan] [-SpotFix]
[-ThrottleLimit <Int32>] [-Confirm] [-WhatIf] [<CommonParameters>]
Repair-Volume [-CimSession <CimSession[]>] [-OfflineScanAndFix] [-Scan] [-SpotFix] [-ThrottleLimit <Int32>]
[-Confirm] [-WhatIf] [<CommonParameters>]
Repair-Volume [-CimSession <CimSession[]>] [-OfflineScanAndFix] [-Scan] [-SpotFix] [-ThrottleLimit <Int32>] -Path
<String[]> [-Confirm] [-WhatIf] [<CommonParameters>]
Repair-Volume [-CimSession <CimSession[]>] [-OfflineScanAndFix] [-Scan] [-SpotFix] [-ThrottleLimit <Int32>]
-FileSystemLabel <String[]> [-Confirm] [-WhatIf] [<CommonParameters>]
Repair-Volume [-CimSession <CimSession[]>] [-OfflineScanAndFix] [-Scan] [-SpotFix] [-ThrottleLimit <Int32>]
-ObjectId <String[]> [-Confirm] [-WhatIf] [<CommonParameters>]
Scan volume without attempting to repair it
To prevent disrupting a volume’s availability, you can scan a volume without attempting to repair it. All detected corruptions are added to the $corrupt system file. This is equivalent to running chkdsk /scan:
PS C:\WINDOWS\system32> Repair-Volume -DriveLetter C -Scan NoErrorsFound
Fix issues logged in the $corrupt system file
So what do you do if a scan finds errors and adds them to the $corrupt system file? You can use SpotFix to only take the volume offline for the time needed to fix those identified errors. This is equivalent to running chkdsk /spotfix:
PS C:\WINDOWS\system32> Repair-Volume -DriveLetter C -SpotFix NoErrorsFound
Take a volume offline for a full scan and fix any errors
If you are actively experiencing problems, you can justify taking the volume offline in order to perform a full scan and fix any errors found along the way. This requires the most time but is also the most comprehensive. This is equivalent to running chkdsk /f:
PS C:\WINDOWS\system32> Repair-Volume -DriveLetter C -OfflineScanAndFix
NoErrorsFound
Repair multiple volumes with a single command
If you want to scan more than one volume, you can specify multiple drive letters in the -DriveLetter parameter. For example, if your computer had drives C, D, and E, specify CDE:
PS C:\WINDOWS\system32> Repair-Volume -DriveLetter CDE -Scan
Repair volumes without letter drives
Not all volumes have a letter drive assigned. For example, you might have a System or Recovery partition. You can run Repair-Volume against these volumes using the -FileSystemLabel parameter.
PS C:\WINDOWS\system32> Get-Volume
DriveLetter FriendlyName FileSystemType DriveType HealthStatus OperationalStatus
----------- ------------ -------------- --------- ------------ -----------------
FAT32 Fixed Healthy OK
C NTFS Fixed Healthy OK
D Unknown CD-ROM Healthy Unknown
Recovery NTFS Fixed Healthy OK
PS C:\WINDOWS\system32> Repair-Volume -FileSystemLabel Recovery -Scan
NoErrorsFound
Repair volumes on a remote computer
If you can establish a CIM Session to a remote computer, you can use the -CIMSession parameter of Repair-Volume to run repair actions remotely.
Not all chkdsk functions available
While arguably the most popular chkdsk functions are available with Repair-Volume, a quick look at chkdsk /? will show some less used and more granular controls which are NOT available in Repair-Volume. However, for most standard use cases, Repair-Volume is an adequate PowerShell replacement for the traditional command line tool chkdsk.
Reference
- Repair-Volume | docs.microsoft.com
Leave a Reply