major update to override Write-Output func
This commit is contained in:
+16
-17
@@ -1,41 +1,40 @@
|
||||
$ScheduleCheckDisk = $false
|
||||
# Run SFC to check the filesystem, convert the result from Unicode to UTF8, delete the intermediate $tempFile
|
||||
$tempFile = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), [System.IO.Path]::GetRandomFileName())
|
||||
$(sfc.exe /scannow) | Out-File $tempFile
|
||||
Set-Content -Path $tempFile -Value $(Get-Content -Path $tempFile -Encoding Unicode) -Encoding UTF8
|
||||
$SFCOutput = Get-Content -Path $tempFile
|
||||
Remove-Item $tempFile -Force -ErrorAction SilentlyContinue
|
||||
|
||||
# Run the System File Checker to scan for and repair any problems with protected system files
|
||||
LogMsg "Running System File Checker"
|
||||
$SFCOutput = $(sfc /scannow) | Out-String
|
||||
LogMsg $SFCOutput
|
||||
|
||||
$SFCOutputWithSpaces = " W i n d o w s R e s o u r c e P r o t e c t i o n d i d n o t f i n d a n y i n t e g r i t y v i o l a t i o n s ."
|
||||
$SFCOutputWithoutSpaces = "Windows Resource Protection did not find any integrity violations."
|
||||
If ( !($SFCOutput -match $SFCOutputWithSpaces) -or !($SFCOutput -match $SFCOutputWithoutSpaces) ) { $ScheduleCheckDisk = $true }
|
||||
# Examine $SFCOutput for integrity violations, if found make sure chkdsk runs at the next boot
|
||||
If ( $SFCOutput -contains 'Windows Resource Protection did not find any integrity violations.' ) { $ScheduleCheckDisk = $false } Else { $ScheduleCheckDisk = $true }
|
||||
|
||||
# Run enhanced DISM for Windows 8 and higher endpoints
|
||||
If ( IsWindowsVersion -ge "6.2" )
|
||||
{
|
||||
$BeginDISMRun = $(Get-Date).AddSeconds(-1)
|
||||
$BeginDISMRun = (Get-Date)
|
||||
|
||||
LogMsg "Beginning repair of Windows Component Store"
|
||||
Write-Output "Beginning repair of Windows Component Store"
|
||||
Start-Process "dism.exe" -ArgumentList "/online /cleanup-image /restorehealth" -Wait
|
||||
|
||||
LogMsg "Beginning cleanup of superceded components in Windows Component Store"
|
||||
Write-Output "Beginning cleanup of superceded components in Windows Component Store"
|
||||
Start-Process "dism.exe" -ArgumentList "/online /cleanup-image /startcomponentcleanup" -Wait
|
||||
|
||||
$EndDISMRun = $(Get-Date).AddSeconds(1)
|
||||
|
||||
# Adding results of DISM log file to this log file
|
||||
LogMsg "Beginning Windows Component Store log data collection"
|
||||
Write-Output "Beginning Windows Component Store log data collection"
|
||||
Get-Content -Path "${Env:WinDir}\Logs\DISM\dism.log" | Select-String -Pattern '^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})' |
|
||||
ForEach-Object {
|
||||
If ( ((Get-Date $_.Line.Substring(0,19)) -gt $BeginDISMRun) -and ((Get-Date $_.Line.Substring(0,19)) -le $EndDISMRun) ) {
|
||||
LogMsg $_.Line
|
||||
Write-Output $_.Line
|
||||
}
|
||||
}
|
||||
LogMsg "Completed Windows Component Store log data collection"
|
||||
Write-Output "Completed Windows Component Store log data collection"
|
||||
}
|
||||
Else { LogMsg "Online image cleanup and restoration is only supported on Windows 8 and higher" }
|
||||
Else { Write-Output "Online image cleanup and restoration is only supported on Windows 8 and higher" }
|
||||
|
||||
# Schedule Check Disk if needed
|
||||
If ( $ScheduleCheckDisk ) {
|
||||
LogMsg "Check Disk scheduled to repair disk at next boot"
|
||||
Write-Output "Check Disk scheduled to repair disk at next boot"
|
||||
& echo y | chkdsk /F /R /X
|
||||
}
|
||||
Reference in New Issue
Block a user