Disk clean up scripts for Windows

Options
heimir
heimir Member Posts: 16

I have tried 4-5 scripts to use for auto remedy for low disk space for Windows devices.

Every single one of them fails.

Support says they dont know if the scripts work or not just that they are not malicious. One thing that was interesting is that Atera has almost a 1000 scripts but knowing that they may or may not work is a problem.

Can someone recommend a script that does a good disk clean that will work in response to an alert?

Comments

  • heimir
    heimir Member Posts: 16
    Options

    Also interesting to see scripts from Syncro in the library.

    #Restart-Computer TODO - Syncro cannot currently reboot a computer from scripts

  • iectechbrian
    iectechbrian Member Posts: 144 ✭✭✭✭
    Options

    I'm afraid that I don't have any advice, but hopefully this bumps it to help others see it!

  • iectechbrian
    iectechbrian Member Posts: 144 ✭✭✭✭
    edited June 19
    Options

    Also, welcome to the community @heimir! Normally people are very helpful here.

  • heimir
    heimir Member Posts: 16
    Options

    Thanks.

    Is it common that most scripts dont work?

  • iectechbrian
    iectechbrian Member Posts: 144 ✭✭✭✭
    Options

    It depends on what the goal is. Some can be very finicky, some work right off the bat. That being said, most of the time community members will normally be discussing solutions for problems like this within about 24 hours. I have noticed, sadly, that community discussions overall have dropped off a bit since the pay for AIT debacle started. So I wish you the best of luck for sure!

  • heimir
    heimir Member Posts: 16
    Options

    @iectechbrian

    The goal is the go to the library and pick a script that works.

    But so far its not the case.

    im not aware of the AIT debacle, Can you fill me in?

  • iectechbrian
    iectechbrian Member Posts: 144 ✭✭✭✭
    Options

    Is that the Atera Script Library? (Just to make sure I understand correctly.)

    For the AIT issue, look at this discussion. It goes over the whole thing from the initial shift through today:

  • iectechbrian
    iectechbrian Member Posts: 144 ✭✭✭✭
    Options

    Also, as a heads up, you can get points on the community and then get rewards for activities here. Each like you get on any post or comment each count as one point. (Comments or posts themselves do not count, but I think that is to discourage people from spamming useless posts just to get points.) To help you get started, I have liked each of your comments and your initial post.

    For more details you can view these three posts that detail the program, as well as a way to quickly get points for reviewing Atera:

  • heimir
    heimir Member Posts: 16
    Options

    Yes the Atera library.

    Will check out the thread. Thanks I appreciate you and your interaction.

  • gilgi
    gilgi Administrator, Moderator Posts: 100 admin
    Options

    Could you please share the script name?
    The only syncro related script I found was 'uninstall syncro' which is useful for people migrating.

    As for your original post - I expect that the votes don't lie - filtering by popularity should indicate useful ones.
    https://app.atera.com/new/admin/scripts

    There is also the top scripts and a blog item but I understand you are requesting something specific.

    Lastly, I'll run a check with our dev team if we can improve script moderation to verify usability.

  • tanderson
    tanderson Member Posts: 243 ✭✭✭✭
    Options

    @heimir Almost every script from the shared script library that I have tried does not work. I have asked Atera to monitor this more closely for two years, but it doesn't seem like a priority to them. If they don't know if a script works, they don't know if one is malicious. Also, most of the scripts are probably being made using the built-in ChatGPT, which is basically useless at making working scripts.

    In my honest opinion, I am starting to get Kaseya vibes from Atera, which totally sucks. I have enjoyed being a customer of Atera, but in the last 15 months, I have seen them completely ignore actual customer needs to promote features that don't work well "AI." Instead of ensuring their script library is vetted, and every script works, they are going to all these conventions and advertising how amazing their AI is when it doesn't really do anything useful at this time.

    A shared script library is useless and dangerous if support tells you they don't know if it works.

    They have focused more on the way the product looks than on the way it works. I do enjoy the updated interface, but if your product has tons of issues with functionality, you are going to lose clients. In my opinion, this seems to be the case being so active on the community page and Reddit. And if you are losing demand, you shouldn't raise the price. That is only going to force more clients out the door.

    They do campaigns like review us on whatever site and get a $30 gift card. Well, if they pay out for 5000 reviews, that's $150,000 (not saying thats their budget just putting out figures) that could have gone to a developer or two to review the script library and make sure everything on there works.

    A good product means a good review for free from clients. You don't need to spend so much on advertising and getting reviews. Spend it on development.

    Rant over

  • derek
    derek Member Posts: 32 ✭✭✭
    Options

    I have used a number od scripts from the Library for disk space an they all work well. Have you tried running the script using the run script and selecting the script Before attaching it to an alert ?

  • heimir
    heimir Member Posts: 16
    Options

    Yes, we did and they failed.

    Its strange. We get weird errors like "cant connect to the device" when you run the script but it runs anyway.
    Have not spend much time since I tried all this a few days ago.
    I think some might have to do with requiring admin rights to run.

  • heimir
    heimir Member Posts: 16
    Options

    And im sure some of this is also due to lack of understanding on my part.

  • mjones
    mjones Member Posts: 169 ✭✭✭✭
    Options

    I have tried to publish several of my scripts for the last 6 months and they just seem to sit there as "Pending".
    Aside from that there is frankly a bunch of trash in there that has no comments and terrible naming. I personally have stopped using what is in there since it's not very reliable and not up to date at all.

    Here is what I have been using for disk cleanups on my machines. It's an amalgamation of various things I have found that seemed to work well. It's definitely not perfect and often fails at some point depending on the machine. It always times out, so don't wait around for it to finish
    I have commented out some of the more aggressive commands.
    Use at your own discretion.

    ##_Gets total disk space available before cleaning starts
    $diskBefore = (Get-WmiObject Win32_LogicalDisk).FreeSpace | Measure-Object -Sum
    $before = [math]::Round($diskBefore.Sum/1MB,2)
    Write-Host "Starting Disk Usage: $before MB" ##_Disk Cleanup
    ##_Create reg keys
    if (!(Test-Path("HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files"))) { New-Item "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files" -Force | New-ItemProperty -Name 'LastAccess' -Value '2' -Force | Out-Null; } else { Get-Item "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files" | New-ItemProperty -Name 'LastAccess' -Value '2' -Force | Out-Null;} $regKeys = @( "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active Setup Temp Folders", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\BranchCache", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Downloaded Program Files", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Internet Cache Files", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Memory Dump Files", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Old ChkDsk Files", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Previous Installations", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Recycle Bin", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\RetailDemo Offline Content", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Service Pack Cleanup", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Setup Log Files", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\System error memory dump files", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\System error minidump files", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Setup Files", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Thumbnail Cache", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Update Cleanup", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Upgrade Discarded Files", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Defender", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting Files", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting Archive Files", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting Queue Files", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting System Archive Files", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting System Queue Files", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows ESD installation files", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Reset Log Files", "HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Upgrade Log Files") foreach($key in $regKeys){ if (!(Test-Path("$key"))) { New-Item "$key" -Force | New-ItemProperty -Name 'StateFlags0420' -Value '2' -Force | Out-Null; } else { Get-Item "$key" | New-ItemProperty -Name 'StateFlags0420' -Value '2' -Force | Out-Null;} } ##_Run Disk Cleanup Start-Process -Wait "$env:SystemRoot\System32\cleanmgr.exe" -ArgumentList "/sagerun:420" ##_Purge the Temp folders
    ##Remove-Item -Path $env:TEMP* -Recurse -Force
    ##System Temp
    $systemTempPath = Join-Path -Path $env:windir -ChildPath '\Temp'
    Get-ChildItem -Path $systemTempPath | Where-Object { $.LastWriteTime -lt (Get-Date).AddDays(-30) } | Remove-Item -Recurse -Force -Confirm:$false ##_User Temp $userProfiles = Get-ChildItem -Path C:\Users -Directory ##_Iterate through each user profile foreach ($userProfile in $userProfiles) { $userName = $userProfile.Name $tempFolderPath = Join-Path -Path $userProfile.FullName -ChildPath 'AppData\Local\Temp' ##_Check if the "\AppData\Local\Temp" folder exists for the user if (Test-Path -Path $tempFolderPath -PathType Container) { ##_Cleanup all files in "\AppData\Local\Temp" for the user that are older than 30 days Get-ChildItem -Path $tempFolderPath | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-30) } | Remove-Item -Recurse -Force -Confirm:$false } else { Write-Host "No Temp folder found for $userName." } } ##_Remove junk Windows Apps
    ##_List Packages
    ##_Get-AppxPackage -AllUsers | Select Name, PackageFullName get-appxpackage -AllUsers *BingNews* | remove-appxpackage -AllUsers get-appxpackage -AllUsers *WindowsMaps* | remove-appxpackage -AllUsers get-appxpackage -AllUsers *YourPhone* | remove-appxpackage -AllUsers get-appxpackage -AllUsers *xboxapp* | remove-appxpackage -AllUsers get-appxpackage -AllUsers *Microsoft.XboxApp* | remove-appxpackage -AllUsers get-appxpackage -AllUsers *Microsoft.Xbox.* | remove-appxpackage -AllUsers get-appxpackage -AllUsers *XboxGamingOverlay* | remove-appxpackage -AllUsers get-appxpackage -AllUsers *XboxIdentityProvider* | remove-appxpackage -AllUsers get-appxpackage -AllUsers *XboxSpeechToTextOverlay* | remove-appxpackage -AllUsers get-appxpackage -AllUsers *SkypeApp* | remove-appxpackage -AllUsers get-appxpackage -AllUsers *XboxOneSmartGlass* | remove-appxpackage -AllUsers get-appxpackage -AllUsers Microsoft.windowscommunicationsapps | remove-appxpackage -AllUsers get-appxpackage -AllUsers *ZuneMusic* | remove-appxpackage -AllUsers get-appxpackage -AllUsers *ZuneVideo* | remove-appxpackage -AllUsers ##_Empty the Recycle Bin
    $driveName = (Get-ChildItem -Path Env:\SystemDrive).Value
    Remove-Item -Path $driveName`$recycle.bin -Recurse -Force -Confirm:$false ##_Clean up system packages (C:\Windows\WinSxS)
    #dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase ##_Gets the available space of all drives after cleaning
    $diskAfter = (Get-WmiObject Win32_LogicalDisk).FreeSpace | Measure-Object -Sum ##_Uses the values from the total disk space used before and after this script to calculate
    ##_total space saved, then converts it to MBs for easier reading
    $after = [math]::Round($diskAfter.Sum/1MB,2)
    $saved = [math]::Round(($before - $after),2)
    $savedGBs = [math]::Round(($saved * 1024 * 1024 / 1GB),2)
    ##_If there is less space than before the script started just report back 0
    If($saved -gt 0) {
    $saved = 0
    } ##_Formats the output so we can split vars
    Write-Output "before=$before|after=$after|spaceSaved=$($saved)MBs|spaceSavedGBs=$($savedGBs)GBs"
    Write-Host "Ending Disk Usage: $after MB"
    Write-Host "Ending Saved: $saved MB" Exit 0

  • mjones
    mjones Member Posts: 169 ✭✭✭✭
    Options
    shutdown -r -t 0
    

    This should work regardless if it's running in CMD or PowerShell

  • heimir
    heimir Member Posts: 16
    Options

    So a script that has 27 votes has over 15000 clones. You want to tell me that "votes dont lie" but it makes no sense. 15700 clones ONLY got 27 likes, what do you think that means?

  • iectechbrian
    iectechbrian Member Posts: 144 ✭✭✭✭
    Options

    Thank you @mjones for helping out!

  • gilgi
    gilgi Administrator, Moderator Posts: 100 admin
    Options

    Thanks for making the point, I see what you mean.
    This area requires a re-look from our side product wise because it's not reflecting practice.

    What UX would you like to see to improve the indication of quality and popularity?

  • heimir
    heimir Member Posts: 16
    Options

    @mjones

    Thank you for that script.

  • stuarthill
    stuarthill Member Posts: 7 ✭✭
    edited June 28
    Options

    We use a Tier1 cleanup script that executes automatically when a disk-space alert is breached, this uses mainly Windows' Disk Cleanup tool to perform the bulk of actions, plus some specific safe deletions and some reporting.

    The script will typically time-out if run manually giving the "Cannot reach agent" BS but completes when you look into the recent processes page.

    I was unable to post the 243 lines of powershell, as it breaks my ability to post :
    "Body is 1969 characters too long" PM me for a copy if required.


    I have a Tier2 version that also empties users recycle Bin etc.


    Regards the scripting generally, I've never used the Atera Copilot AI for generating a script. I find that the natural flow of conversation within ChatGPT far superior, after the initial script creation, for the ongoing improvements to the script as you run it and then think of someway to fix/make it better.


    I'd prefer they binned all their AI approach they are pushing to us and instead focussed on grass-roots improvements, such as allowing better filtering within the scripting page, or the ability to turn OFF the Shared Scripts Library, that takes ~24 seconds to load the /scripts page each time … very annoying.

  • tanderson
    tanderson Member Posts: 243 ✭✭✭✭
    Options

    @stuarthill do you mind sending my way I would like to view both the T1 and T2 to see if it has anything left out from what we are doing.

  • heimir
    heimir Member Posts: 16
    Options

    @stuarthill

    I would love to take a look at the scripts if you wouldnt mind.

    Thank you for responding.

  • gilgi
    gilgi Administrator, Moderator Posts: 100 admin
    Options

    @mjones
    I have tried to publish several of my scripts for the last 6 months and they just seem to sit there as "Pending".

    Thanks for flagging. Took me a bit of probing around but I've now established the connection with the relevant devs in charge of this domain, here is the bottom line bullets:

    - We will upgrade the cadence in which we review submissions.
    - The last review was in April.
    - You mention your submission is still set as 'Pending' for 6 months, but the last one i saw from your account was from October, could you provide me the name of the pending item to check? here or in DMs, I can help :)
    - Now that I have a better grasp of this process I can push for better service and support to the community shared script library, and a review of this process from product standpoint is a relevant request, so thank you everyone who contributed in the discussion.

  • mjones
    mjones Member Posts: 169 ✭✭✭✭
    Options