Start-WindowsCleanup

Discussion in 'Scripting' started by GodHand, Sep 18, 2019.

  1. GodHand

    GodHand MDL Addicted

    Jul 15, 2016
    529
    826
    30
    #1 GodHand, Sep 18, 2019
    Last edited: Aug 26, 2020
    Updated 08/26/2020
    - The OS is now checked before removing shadow copies (restore points) to make sure it is not a version of Windows Server.
    - Added additional default and Microsoft Edge removal paths.
    - Added the clearing of the App Compat Cache and CD burning registry keys.

    I cannot post the full code of the module any longer due to exceeding the character limit for a single post, but I created a GitHub Gist for it where you can view it and download it:

    Start-WindowsCleanup on GitHub
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. abbodi1406

    abbodi1406 MDL KB0000001

    Feb 19, 2011
    11,066
    47,198
    340
    The issues actually start with build 18362 (v1903), 18363 is just registry version for 1909 :)
     
  3. GodHand

    GodHand MDL Addicted

    Jul 15, 2016
    529
    826
    30
    Thanks for the clarification. I changed it from 18363 to 18362.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. GodHand

    GodHand MDL Addicted

    Jul 15, 2016
    529
    826
    30
    Added optional Microsoft Edge cache directory clean-up to the -Include parameter set.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. vigipirate

    vigipirate MDL Member

    Feb 24, 2011
    195
    47
    10
    please create broser bat or cmd
     
  6. GodHand

    GodHand MDL Addicted

    Jul 15, 2016
    529
    826
    30
    What?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. coleoptere2007

    coleoptere2007 MDL Guru

    Apr 8, 2008
    2,951
    1,571
    90
    the guy ask you to create a batch or cmd file :laie:
     
  8. GodHand

    GodHand MDL Addicted

    Jul 15, 2016
    529
    826
    30
    That's not going to happen.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  9. GodHand

    GodHand MDL Addicted

    Jul 15, 2016
    529
    826
    30
    Updated with clean-up improvements.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. rayleigh_otter

    rayleigh_otter MDL Expert

    Aug 8, 2018
    1,121
    926
    60
    I would love to see bat/cmd versions(cos i know my way around them) of powersmell stuff but you have to accept and respect a developers choice. We have 2 choices, try to create our own bats or learn powersmell.
     
  11. MMIKEE

    MMIKEE MDL Senior Member

    Oct 6, 2012
    336
    301
    10
    GUI's <and / or> bat/cmd scripts to be able to use @GodHand powershell scripts would be Greatly Appreciated since NOT every MDL member is a powershell expert or even remotely close to being one...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. GodHand

    GodHand MDL Addicted

    Jul 15, 2016
    529
    826
    30
    You do not have to be anywhere close to a "PowerShell expert" to run any of the functions I post - that's why I post them.

    Functions can be copied and then pasted right into an elevated PowerShell console and then executed by typing the function name, or they can be saved saved to a .ps1 file and called directly within a PowerShell console like you'd call one batch script from another.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  13. rayleigh_otter

    rayleigh_otter MDL Expert

    Aug 8, 2018
    1,121
    926
    60
    Knowing something works isnt enough for me, i like to know how and why, thats how i learnt the basics of bat's and cmd's.
     
  14. rayleigh_otter

    rayleigh_otter MDL Expert

    Aug 8, 2018
    1,121
    926
    60
    Just out of interest @GodHand, do you know of a tool that converts bats and cmds to powershell? I prefer to use one type of file only and combine stuff into 1 large script rather than seperate bats/cmds and powershells.
     
  15. GodHand

    GodHand MDL Addicted

    Jul 15, 2016
    529
    826
    30
    #15 GodHand, Nov 10, 2019
    Last edited: Nov 10, 2019
    (OP)
    There is no tool that can do that. PowerShell code logic and syntax are completely different and you can't just convert it - you have to rewrite it.

    You can execute bat/cmd scripts within PowerShell and monitor them using many PowerShell's cmdlets, though, which is not hard. Likewise, you can encode PowerShell scripts and execute them within bat/cmd scripts.

    If you are interested in learning and knowing the 'how and why,' why are you asking me to create a version in a depreciated format for you instead of taking the time to look at the code to understand exactly what it's doing?

    It's not a complicated function.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. rayleigh_otter

    rayleigh_otter MDL Expert

    Aug 8, 2018
    1,121
    926
    60
    Im not. You create a PS script in that format only as is your right to do so i want to learn PS so i know what you do and how you do it. Im backing you on your choice of PS scripts only, im on your side. :)
     
  17. GodHand

    GodHand MDL Addicted

    Jul 15, 2016
    529
    826
    30
    Updated 11-14-2019: Added additional logging and update clean-up locations. Tweaked the preclean-up and post clean-up results that get returned. Added some code changes and optimizations.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  18. GodHand

    GodHand MDL Addicted

    Jul 15, 2016
    529
    826
    30
    Updated 01-16-2020:
    - Added additional directories for removal.
    - Added methods to clean-up the component store and/or reset the image base using a background job.
    - Added a timed pop-up verification for the removal of download folders' contents in case it was accidentally entered when calling the function.
    - Assorted other code changes.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  19. Windows_Addict

    Windows_Addict MDL Addicted

    Jul 19, 2018
    624
    1,164
    30
    @vigipirate @rayleigh_otter @MMIKEE

    Batch script to call Powershell function,

    Save the Powershell (.ps1) script and batch script (.cmd) in the same directory.

    Code:
    @echo off
    
    reg query HKU\S-1-5-19 1>nul 2>nul || (
    echo ==== Error ====
    echo Right click on this file and select 'Run as administrator'
    echo Press any key to exit...
    pause >nul
    exit /b
    )
    
    REM                                                   File name                 Function name
    powershell -ExecutionPolicy ByPass -command ". "%~dp0Start-WindowsCleanup.ps1"; Start-WindowsCleanup;"
    pause
    It works with GodHand's other script too,
    P.S. To avoid any possible errors, make sure that the pathname does not have spaces or special characters.
     
  20. GodHand

    GodHand MDL Addicted

    Jul 15, 2016
    529
    826
    30
    Updated 02-13-2020
    - Multiple code improvements.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...