Advertisement
Cogger

I0-CleanMgr-Modifications.ps1

Mar 28th, 2023 (edited)
1,016
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ########################################################################################################################
  2. #=====[ Clean Manager ]=====#
  3. ########################################################################################################################
  4.  
  5. #=====[ Creating Clean Manager Sageset ]=====#
  6.  
  7. $Flags = "StateFlags0110"
  8. $Prefix_RegHive = "Registry::HKEY_LOCAL_MACHINE"
  9. $Prefix_RegPath = "HKLM:"
  10. $RegClnPath = "\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches"
  11.  
  12. $RegHive = $Prefix_RegHive + $RegClnPath
  13. $RegPath = $Prefix_RegPath + $RegClnPath
  14.  
  15. $RegistryArray= @(
  16.    
  17.     "Active Setup Temp Folders"              # Temporary Setup Files
  18.     "BranchCache"                            # Branch Cache (WAN bandwidth optimization)
  19.     #"Content Indexer Cleaner"               # Catalog Files for the Content Indexer (deletes all files in the folder c:\catalog.wci)
  20.     "Delivery Optimization Files"            # Delivery Optimization Files (service to share bandwidth for uploading Windows updates)
  21.     "Diagnostic Data Viewer database Files"  # Diagnostic data viewer database files (Windows app that sends data to Microsoft)
  22.     "D3D Shader Cache"                       # Direct X Shader cache (graphics cache, clearing this can can speed up application load time.)
  23.     "Downloaded Program Files"               # Downloaded Program Files (ActiveX controls and Java applets downloaded from the Internet)
  24.     #"Downloads Folder"                      # Downloads Folder (Automatically emptying this is probably a bad idea.)
  25.     "Internet Cache Files"                   # Temporary Internet Files
  26.     #"Language Pack"                         # Language resources Files (unused languages and keyboard layouts)
  27.     #"Offline Pages Files"                   # Offline Files (Web pages)
  28.     "Old ChkDsk Files"                       # Old ChkDsk Files
  29.     #"Recycle Bin"                           # Recycle Bin Automatically emptying the Recycle Bin is almost never a good idea.
  30.     #"RetailDemo Offline Content"            # Retail Demo
  31.     "ServicePack Cleanup"                    # Update package Backup Files (old versions)
  32.     "Setup Log Files"                        # Setup Log files (software install logs)
  33.     "System error memory dump files"         # System Error memory dump files (These can be very large if the system has crashed)
  34.     "System error minidump files"            # System Error minidump files (smaller memory crash dumps)
  35.     "Temporary Files"                        # Temporary Files (%Windir%\Temp and %Windir%\Logs)
  36.     "Update Cleanup"                         # Windows Update Cleanup (old system files not migrated during a Windows Upgrade)
  37.     #"User file versions"                    # User file history (Settings > Update & Security > Backup.)
  38.     "Thumbnail Cache"                        # Thumbnails (Explorer will recreate thumbnails as each folder is viewed.)
  39.     "Windows Defender"                       # Windows Defender Antivirus
  40.     "Windows Error Reporting Files"          # Windows error reports and feedback diagnostics
  41.     "Windows Upgrade Log Files"              # Windows Upgrade log files
  42.    
  43. )
  44.  
  45.  
  46. foreach ($Key in $RegistryArray) {
  47.  
  48.     $SNFlags = $null ; $SNData = $null
  49.     $RegDirHive = $RegHive + "\" + $Key
  50.     $RegDirPath = $RegPath + "\" + $Key
  51.  
  52.     if( Test-Path -Path $RegDirPath ){
  53.         $Registrykeys = Get-Item -Path $RegDirPath
  54.         $RegistryData = $Registrykeys | Select-Object -ExpandProperty Property | ForEach-Object {
  55.         $name = $_
  56.         $data = "" | Select-Object -Property Name, Path, Type, Data #creates an empty
  57.         $data.Name = $name
  58.         #$data.Type = $Registrykeys.GetValueKind($name)
  59.         $data.Data = $Registrykeys.GetValue($name)
  60.         $data.Path = "Registry::$Registrykeys"
  61.         $data
  62.         }
  63.  
  64.         $RegistryData |  ForEach-Object {
  65.             if( $_.Name -Like "StateFlags*" ) {
  66.                 $SNFlags = $_.Name
  67.                 $SNData = $_.Data
  68.                 $SNPath = $_.Path } }
  69.  
  70.         if( Test-Path -Path $SNPath ){
  71.             $SetPath    = $SNPath + "\" + $SNFlags
  72.             $SetDynPath = $SNPath + "\" + $SNFlags
  73.             $defFlag    = (Get-ItemProperty -Path $SNPath | Select-Object -ExpandProperty $Value).$SNFlags
  74.            
  75.             if( $defFlag -Eq "2" ){ <# No Action Needed #> } else {
  76.                 New-Item -Path "$RegDirPath" | Out-Null -EA SilentlyContinue
  77.                 New-ItemProperty -Path "$RegDirPath" -Type DWord -Name "$Flags" -Value "2" -Force -EA SilentlyContinue }
  78.  
  79.          } else {
  80.             New-Item -Path "$RegDirPath" | Out-Null -EA SilentlyContinue
  81.             New-ItemProperty -Path "$RegDirPath" -Type DWord -Name "$Flags" -Value "2" -Force -EA SilentlyContinue
  82.          }
  83.  
  84.     } else {
  85.         New-Item -Path "$RegDirPath" | Out-Null -EA SilentlyContinue
  86.         New-ItemProperty -Path "$RegDirPath" -Type DWord -Name "$Flags" -Value "2" -Force -EA SilentlyContinue
  87.     }
  88.  
  89. }
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement