Forum Discussion
Surya2023
Jul 27, 2022Copper Contributor
SFC scan using Batch file or Powershell
Hi,
Trying to run SFC scan every day using task scheduler ,however the result are storing in default location C:\Windows\Logs\CBS CBS text file ,
Written Batch file ,to run sfc scan and save the output in user desktop or local disk C
--------- Below 2 lines copied and saved as .bat -------
sfc /scannow
findstr /c:"[SR]" %windir%\Logs\CBS\CBS.log > C:\sfclogs.txt
however it was failed to run.
+++++++++++++++++++++++++++++++++
have PowerShell script but i don't know where to place sfc /scannow command in the script
Get-Content -Path "$env:windir\Logs\CBS\CBS.log" |
Where-Object { $input -like "*[SR]*" } |
Out-File -FilePath "$env:USERPROFILE\Desktop\sfcdetails.txt"
+++++++++++++++++++++++++++++++++++++
Could you please suggest me here.
- Yes, you can use the following
"$env:USERPROFILE\Desktop\$(get-date -Format "ddM-MM-yyyy--hh-mm-ss")"
-----------
If the answer help, Please click on Best Response and give a like 🙂
- farismalaebSteel Contributor
On the top of Get-Content
Sfc /scannow Get-Content -Path "$env:windir\Logs\CBS\CBS.log" |Where-Object { $input -like "*[SR]*" } |Out-File -FilePath "$env:USERPROFILE\Desktop\sfcdetails.txt"
---------------
If this answer help, Please click on Best Response and hit the like 🙂
- Surya2023Copper Contributorfarismalaeb : Thanks for your input. Since i was using for daily scan in scheduled task .
So in the script could you please suggest to keep existing file and create a new file with respective date- farismalaebSteel Contributor
Yes
sure you can use the following as a FilePath
-FilePath "$env:USERPROFILE\Desktop\$(get-date -Format "DD-MM-yyyy").txt"