We have completed the script for your request, it will run SFC in the background and return Logs to endpoint. As you asked script would run when system meets idle state, cresting task and scheduling is he best way but it allow you to run the Script whenever system is Idle means it will deviate you from accuracy of SFC logs. In order to avoid that we request you to go by system is available state in background.
Please refer the following script to get SFC logs to endpoint.
Note : Run as System User
</b>
import os, ctypes
import datetime
workdir=os.environ['PROGRAMDATA']+r'\c1_temp'
if not os.path.exists(workdir):
os.makedirs(workdir)
save_path=workdir
class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
def __enter__(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def __exit__(self, type, value, traceback):
if self.success:
self._revert(self.old_value)
path=save_path+r'\sfcdetails.txt'
k=datetime.datetime.today().strftime('%Y-%m-%d')
def SFC():
with disable_file_system_redirection():
k=os.popen("sfc /scannow").read()
def text():
with disable_file_system_redirection():
command='findstr /c:"[SR]" %windir%\logs\cbs\cbs.log >'+path
os.popen(command).read()
os.chdir(save_path)
with open(os.path.join(save_path, "sfcdetails"+".txt"), 'r+' ) as f:
g=f.readlines()
for lines in g:
if k in lines:
lines=lines.rstrip("
")
print lines
def remove():
os.remove(path)
SFC()
text()
remove()
<b>