PowerShell/Scripts/check-file-system.ps1

32 lines
723 B
PowerShell
Raw Normal View History

2021-04-21 19:53:52 +02:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
check-file-system.ps1 [<drive>]
.DESCRIPTION
Checks the validity of the file system (needs admin rights)
.EXAMPLE
PS> .\check-file-system.ps1 C
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz / License: CC0
2021-04-05 10:48:34 +02:00
#>
#Requires -RunAsAdministrator
2021-07-15 15:51:22 +02:00
param([string]$Drive = "")
2021-04-05 10:48:34 +02:00
if ($Drive -eq "" ) {
$Drive = read-host "Enter drive (letter) to check"
}
try {
2021-04-05 11:03:12 +02:00
$Result = repair-volume -driveLetter $Drive -scan
if ($Result -ne "NoErrorsFound") { throw "'repair-volume' failed" }
2021-04-05 10:48:34 +02:00
2021-04-16 18:46:03 +02:00
write-host -foregroundColor green "✔️ file system on drive $Drive is clean"
2021-04-05 10:48:34 +02:00
exit 0
} catch {
2021-05-02 21:30:48 +02:00
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2021-04-05 10:48:34 +02:00
exit 1
}