0% found this document useful (0 votes)
18 views2 pages

Windows Component Cleanup

The document describes a Windows cleanup script that stops and starts services, removes and renames folders, registers DLLs, runs DISM and SFC scans, and logs the status and timestamps of each step to a log file. Key steps include stopping and starting Windows update, installer, and cryptographic services, removing the SoftwareDistribution and catroot folders and renaming them, running DISM and SFC scans, and registering OLE controls.

Uploaded by

Nirmal Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Windows Component Cleanup

The document describes a Windows cleanup script that stops and starts services, removes and renames folders, registers DLLs, runs DISM and SFC scans, and logs the status and timestamps of each step to a log file. Key steps include stopping and starting Windows update, installer, and cryptographic services, removing the SoftwareDistribution and catroot folders and renaming them, running DISM and SFC scans, and registering OLE controls.

Uploaded by

Nirmal Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

New-Item -Path C:\ -Name CleanupScript-Status.

log -ItemType file -force


##"Starting Cleanup Script | $(Get-Date -Format HH:mm:ss:ms)" | Out-File "C:\"
$log = "C:\CleanupScript-Status.log"
Add-Content -Path $log "Starting Cleanup Script | $(Get-Date -Format HH:mm:ss:ms)"

Set-Service -Name trustedinstaller -StartupType Automatic


Add-Content -Path $log "Trustedinstaller service started | $(Get-Date -Format
HH:mm:ss:ms)"

Add-content -Path $log "Stopping services | $(Get-Date -Format HH:mm:ss:ms)"

Stop-service bits -force


Add-content -Path $log "BITS Service Stopped | $(Get-Date -Format HH:mm:ss:ms)"

Stop-service wuauserv -force


Add-content -Path $log "Windows Update Service Stopped | $(Get-Date -Format
HH:mm:ss:ms)"

Stop-service msiserver -force


Add-content -Path $log "Windows Installer Service Stopped | $(Get-Date -Format
HH:mm:ss:ms)"

Stop-service cryptsvc -force


Add-content -Path $log "Cryptographic Service Stopped | $(Get-Date -Format
HH:mm:ss:ms)"

Stop-service appidsvc -force


Add-content -Path $log "Application Identity Service Stopped | $(Get-Date -Format
HH:mm:ss:ms)"

Remove-Item -Path "C:\windows\SoftwareDistribution.old" -Force -Recurse


Add-content -Path $log "Software Distribution folder Removed | $(Get-Date -Format
HH:mm:ss:ms)"

Remove-Item -Path "C:\windows\System32\catroot2.old" -Force -Recurse


Add-content -Path $log "Catroot folder Removed | $(Get-Date -Format HH:mm:ss:ms)"

Rename-Item -path "C:\windows\SoftwareDistribution" -NewName "C:\windows\


SoftwareDistribution.old" -force
Add-content -Path $log "Software Distribution folder Renamed | $(Get-Date -Format
HH:mm:ss:ms)"

Rename-Item -path "C:\windows\System32\catroot2" -NewName "C:\windows\System32\


catroot2.old" -force
Add-content -Path $log "Catroot folder Renamed | $(Get-Date -Format HH:mm:ss:ms)"

Add-content -Path $log "Register OLE Controls | $(Get-Date -Format HH:mm:ss:ms)"


regsvr32.exe /s atl.dll
regsvr32.exe /s urlmon.dll
regsvr32.exe /s mshtml.dll

Add-content -Path $log "DISM Scan health is in progress | $(Get-Date -Format


HH:mm:ss:ms)"
dism /Online /Cleanup-image /ScanHealth
Add-content -Path $log "DISM Scan health completed | $(Get-Date -Format
HH:mm:ss:ms)"

Add-content -Path $log "DISM Check health is in progress | $(Get-Date -Format


HH:mm:ss:ms)"
dism /Online /Cleanup-image /CheckHealth
Add-content -Path $log "DISM Check health completed | $(Get-Date -Format
HH:mm:ss:ms)"

Add-content -Path $log "DISM Cleanup is in progress | $(Get-Date -Format


HH:mm:ss:ms)"
dism /Online /Cleanup-image /RestoreHealth
Add-content -Path $log "DISM Cleanup completed | $(Get-Date -Format HH:mm:ss:ms)"

Add-content -Path $log "DISM Component Cleanup is in progress | $(Get-Date -Format


HH:mm:ss:ms)"
dism /Online /Cleanup-image /StartComponentCleanup
Add-content -Path $log "DISM Component Cleanup completed | $(Get-Date -Format
HH:mm:ss:ms)"

Add-content -Path $log "SFC Scan is in progress | $(Get-Date -Format HH:mm:ss:ms)"


Sfc /ScanNow
Add-content -Path $log "SFC Scan completed | $(Get-Date -Format HH:mm:ss:ms)"

Start-service bits
Add-content -Path $log "BITS Service Started | $(Get-Date -Format HH:mm:ss:ms)"

Start-service wuauserv
Add-content -Path $log "Windows Update Service Started | $(Get-Date -Format
HH:mm:ss:ms)"

Start-service msiserver
Add-content -Path $log "Windows Installer Service Started | $(Get-Date -Format
HH:mm:ss:ms)"

Start-service cryptsvc
Add-content -Path $log "Cryptographic Service Started | $(Get-Date -Format
HH:mm:ss:ms)"

Start-service appidsvc
Add-content -Path $log "Application Identity Service Started | $(Get-Date -Format
HH:mm:ss:ms)"

Add-Content -Path $log "Ending Cleanup Script | $(Get-Date -Format HH:mm:ss:ms)"

You might also like