Compare commits

...
2 Commits
Author SHA1 Message Date
dyoder 5cd4e99465 very minor changes 2023-10-05 14:10:02 -04:00
dyoder 8962142931 Write-Output/Error is streamlined
and will send output to the console
2023-10-05 14:09:27 -04:00
2 changed files with 8 additions and 16 deletions
+4 -2
View File
@@ -11,6 +11,7 @@ If ( $SFCOutput -contains 'Windows Resource Protection did not find any integrit
# Run enhanced DISM for Windows 8 and higher endpoints # Run enhanced DISM for Windows 8 and higher endpoints
If ( IsWindowsVersion -ge "6.2" ) If ( IsWindowsVersion -ge "6.2" )
{ {
# Record start of DISM repair
$BeginDISMRun = (Get-Date) $BeginDISMRun = (Get-Date)
Write-Output "Beginning repair of Windows Component Store" Write-Output "Beginning repair of Windows Component Store"
@@ -19,9 +20,10 @@ If ( IsWindowsVersion -ge "6.2" )
Write-Output "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 Start-Process "dism.exe" -ArgumentList "/online /cleanup-image /startcomponentcleanup" -Wait
$EndDISMRun = $(Get-Date).AddSeconds(1) # Record end of DISM repair
$EndDISMRun = (Get-Date)
# Adding results of DISM log file to this log file # Extract results of DISM repair from system log and add them to this log
Write-Output "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})' | 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 { ForEach-Object {
+4 -14
View File
@@ -59,17 +59,15 @@ Function Setup-LogFile {
# Start-Process "cmd.exe" -ArgumentList '/C echo y | some-command' # Start-Process "cmd.exe" -ArgumentList '/C echo y | some-command'
Function Write-Output { Function Write-Output {
param([Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$Message) param([Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$Message)
$Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" Add-Content -Path $Global:LogFile -Value "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") - ${Message}"
$LogEntry = "${Timestamp} - ${Message}" Microsoft.Powershell.Utility\Write-Output $Message
Add-Content -Path $Global:LogFile -Value $LogEntry
} }
# Log an error to the log file # Log an error to the log file
Function Write-Error { Function Write-Error {
param([Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$Message) param([Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$Message)
$Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" Add-Content -Path $Global:LogFile -Value "$(Get-Date -Format "yyyy-MM-dd HH:mm:ss") - Error: ${Message}"
$LogEntry = "${Timestamp} - Error: ${Message}" Microsoft.Powershell.Utility\Write-Error $Message
Add-Content -Path $Global:LogFile -Value $LogEntry
} }
# Function to determine if the current user context is an Administrator # Function to determine if the current user context is an Administrator
@@ -155,14 +153,6 @@ Function Run-Script {
} }
} }
} }
$LogFileContent = (Get-Content $LogFile)
# Write the log file output to the console
If ( $LogFileContent ) { Write-Output $LogFileContent }
# Delete the log file if it's empty
Else { Remove-Item $LogFile -Force }
} }
# Return a Powershell version object from a string # Return a Powershell version object from a string