If ( Is64Bit ) { $BlueScreenView = $Global:ToolsDirectory + '\BlueScreenView-x64.exe' } Else { $BlueScreenView = $Global:ToolsDirectory + '\BlueScreenView-x86.exe' } $BSODReport = $Global:OutputDirectory + '\BSODReport.txt' # Remove existing BSOD report If ( Test-Path $BSODReport ) { Remove-Item $BSODReport -Force -ErrorAction SilentlyContinue } # Run BlueScreenView If ( !(Test-Path $BlueScreenView) ) { Write-Error "File does not exist: ${BlueScreenView}" ; Return } Start-Process $BlueScreenView -ArgumentList "/stext $BSODReport /sort ~1" -Wait # Wait for BSOD report For ($i = 0; $i -lt 1200; $i++) { If ( Test-Path $BSODReport ) { Break } Start-Sleep -Seconds 1 } # Exit if the BSOD report was not created If ( !(Test-Path $BSODReport) ) { Write-Output "BSOD report was not found: ${BSODReport}" ; Return } # Create ticket $BSODReportContent = $(Get-Content -Path $BSODReport) -join "`n" New-RMMTicket -Subject "System Crash on ${Env:COMPUTERNAME}" -InitialIssue $BSODReportContent # Update the ticket New-TicketComment -Comment "It looks like your computer crashed. I'll get this resolved as soon as possible." # Wait a bit Start-Sleep -Seconds 120 # Setup providers for matching BSOD report content $ProviderMicrosoft = 'Microsoft|Windows' # Get the provider data from the most recent BSOD $CulpritProvider = $BSODReportContent[12..13] -join '`n' # Set the billable time $BillableTimeInMinutes = 15 $StartAt = (Get-Date).AddMinutes(-$BillableTimeInMinutes).ToString("o") Switch ( $CulpritProvider ) { { $_ -match $ProviderMicrosoft } { New-TicketComment -Comment "I've analyzed the crash report and it indicates a problem with a Windows component. I'll repair the system now." $TimeEntryNote = "Analysis indicates crash caused by Windows component(s). Scanning and repairing corruption in the system." Create-Syncro-Ticket-TimerEntry -TicketIdOrNumber $TicketID -StartTime $StartAt -DurationMinutes $BillableTimeInMinutes -Notes $TimeEntryNote -UserIdOrEmail $TimeAttributedToUser -ChargeTime "true" $FixWindowsHealth = Download-File -URL 'https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Fix-WindowsHealth.ps1' Start-Sleep -Seconds 120 . $FixWindowsHealth If ( Test-Path $FixWindowsHealth ) { Remove-Item $FixWindowsHealth -Force -ErrorAction SilentlyContinue } } }