Monthly SFC Scan
Summary
This script will run an SFC scan and gather the logs from that scan via console output and the cbs.log
file. It will check for errors and handle each accordingly. In the event that a repair is needed, this script will run a dism /online
repair or a SURT repair on Vista-class devices. It will create, update, and complete tickets based on the results of the process.
Sample Run
Dependencies
- Must be allowed to create scheduled tasks.
- Must be allowed to create event log items.
Variables
Document the various variables in the script. Delete any section that is not relevant to your script.
Name | Description |
---|---|
surtUrl | The URL for the SURT file for the given system. |
numruns | The current scan iteration |
DismCount | The current DISM iteration |
Theme | Used to pass variables and logs to the logging and upload file section |
SFCResult | The filtered result of the SFC scan |
CBSResult | The filtered result of the CBS log file. |
Destination | Derived from splitting a variable that determines the label in the script to go to next |
psoutwhy | Why the destination label to go to was determined. |
ImportantInfo | Used for logging and the message body of the ticket for important information relating to a restart being required scenario |
DismResult | The result of running a DISM command if necessary. |
Process
- Set up the environment by stopping the
wuauserv
service, renaming thecbs.log
, and restarting the service. - Set any necessary SURT URL.
- Set any static variables.
- Start the scanning iteration.
- Create any necessary folders and run the SFC scan, gathering only filtered results for logging.
- Log and upload any created file.
- Get the contents of the CBS log file.
- Log and upload any file data.
- Determine what steps need to happen next.
- If a restart is required:
- Set the computer to pending reboot.
- Create a
.ps1
file to re-run the SFC scan after reboot as a scheduled task named 'Proval_Script_Monthly_SFC_Scan'.- After reboot:
- Clear any necessary files/folders.
- Run the SFC scan.
- Write an event log:
- Provider: 'Proval_Script_Monthly_SFC_Scan'
- Event ID: 7395
- Log Name: Application
- Log Level: Information
- Unregister the scheduled job named 'Proval_Script_Monthly_SFC_Scan'.
- After reboot:
- Log all pertinent information, update the ticket, and exit.
- If a restart is required:
- If a repair is needed:
- Ensure we haven't exceeded the 3rd iteration of the run.
- If we have, update the ticket with any pertinent information, log the results, and exit with an error.
- Add a ticket comment.
- If a Vista-class run, check the SURT:
- Determine what label I need to go to.
- If a scan is necessary, go back to root step 4.
- If not repaired, update the ticket with any pertinent information, log the results, and exit with an error.
- If an error occurs, update the ticket with any pertinent information, log the results, and exit with an error.
- Determine what label I need to go to.
- Start the DISM process:
- If it's more than the 3rd attempt, update the ticket with any pertinent information, log the results, and exit with an error.
- Run DISM online cleanup.
- Filter through the results for anything containing "Warning" or "Error".
- Log and upload any files and results.
- If the results don't contain "The operation completed successfully", then go back to step 4 and start the DISM process.
- Finish the ticket.
- Rescan.
- Ensure we haven't exceeded the 3rd iteration of the run.
- If an error is found:
- Log an error, update the ticket, and exit with an error.
- If "Not repaired" is found:
- Log an error, update the ticket, and exit with an error.
- If everything is good:
- Log the result, finish the ticket, and exit.
Output
- Script log
C:/Temp/CBS.Log
C:/Temp/SFC.Log
- Application Event log entry 7395 from 'Proval_Script_Monthly_SFC_Scan'
- Ticket with all related information.