diff --git a/Microsoft/Run_System_File_Checker.ps1 b/Microsoft/Run_System_File_Checker.ps1 new file mode 100644 index 0000000..77f10a5 --- /dev/null +++ b/Microsoft/Run_System_File_Checker.ps1 @@ -0,0 +1,55 @@ +# Script by Timur@0x01337.com +# Date: 2023-11-24 +<# +.DESCRIPTION +Runs the "sfc /scannow" command that finds and fixes errors in Windows system files and returns the result of operation. + +Requires administrator privileges. + +.PARAMETER help +Displays a detailed usage description of this script. + +.EXAMPLE +PS> .\Run-System-File-Checker.ps1 + +.EXAMPLE +PS> .\Run-System-File-Checker.ps1 -help +#> + +# Getting command line parameters +param ( + [parameter(Mandatory = $false)][switch]$help +) + +$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) +$isAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) +if (!$isAdmin) { + Write-Error "This script requires administrator privileges" + exit 1 +} + +# Writing help message +if ($help) { + get-help $MyInvocation.MyCommand.Path -Full + exit 0 +} + +$command = "sfc" +$arguments = "/scannow" + +Write-Host "Running $command $arguments" +try { + $process = Start-Process -Wait -PassThru -NoNewWindow -FilePath $command -ArgumentList $arguments +} +catch { + Write-Error "$_, exit code: $($process.ExitCode)" + exit 1 +} + +if (!$process -or $process.ExitCode -ne 0) { + Write-Error "$command $arguments failed, exit code: $($process.ExitCode)" + exit 1 +} + +Write-Host "$command $arguments finish, exit code: $($process.ExitCode)" +exit 0