C:\Windows\WinSxS\Temp\InFlight\ Deleting Empty Folders


If you want a 100% sure way of deleting files in "C:\Windows\WinSxS\Temp" boot to another OS or even a Windows PE. Permissions mean nothing in these environments. I've done this countless times with no ill effects.
The script grants itself the rights to take ownership of the folders, so there's no need to boot out of Windows.

If a process has locked the folder or file because it's being used, it can be solved by killing the owning process. Since these are "forgotten" folders, there's no risk of that happening.
 

My Computer

System One

  • OS
    Windows 7
Your problem is that you want to reduce backup time, correct? What app do you currently use for backup and do you run it under windows or boot to is stand-alone? Tnx
The folder cleanup impacts any process that needs to scan the filesystem, because it's wasting time to browse folders which have no use.

This would slow down:
- Security software doing a full folder scan​
- Backup solutions which are not volume-based (when you back up a volume, you don't care what's inside the volume)​
- Cleanup tools that do a full folder scan​
- CHKDSK /f (because it has to run integrity checks on all folders)​
- DISM processing updates, because it has to check if there's anything to process​
 

My Computer

System One

  • OS
    Windows 7
Your problem is that you want to reduce backup time, correct? What app do you currently use for backup and do you run it under windows or boot to is stand-alone? Tnx
Not solely to backup, also anti-virus/scan times or just maintance of systems or observations of others. Will use it over a variety of systems.
Different kind of backup solutions, with a variety of configurations. Most will use Backup Exec, some directly to backup hardware. Some systems only has an agent installed, and transfer data during the night to seperate backup server with storage. All depends on the needs of others..
My initial test indicate improved & shorter running times of applications processing those folders. Already tackled a bunch of long running issues. From windows servers, to workstations.

How i see some things are black and white. If you have a large structure and store 80.000empty boxes that you don't need. But you do need count them every year to make an invataris for the yearly balance of what is in storage, would you keep the boxes as it takes extra time to count them every year?
So that extra time is now gone, onces it is a policy, the empty boxes will be trown out every month automaticly. So never waisting any time on it again.
For one system it might be not worth while the work. If you maintain alot more, it adds op.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
A sysadmin knows the worst thing you can do to a system is create an infinite number of folders. The cost for browsing a folder is small, but if you're doing this 80,000 times a row that cost goes up. Not to imagine what happens when you're tasked with running some check once you're inside the folder.
 

My Computer

System One

  • OS
    Windows 7
I use I4W under windows and I4L under standalone boot
24H2 win boot nvme backup to nvme - 86GB data in 52sec. - created a 76GB image.
PXL_20250215_211131097.webpPXL_20250215_211141830.webp
 

My Computers

System One System Two

  • OS
    win 11Pro, 24H2, 26100.3194
    Computer type
    PC/Desktop
    Manufacturer/Model
    DIY
    CPU
    I9-13900k
    Motherboard
    ASUS ROG STRIX Z790-E Gam wifi-6E, latest AMI BIOS 2801
    Memory
    G.Skill Ripjaws S5 32GB Kit DDR5 6000. 6000.
    Graphics Card(s)
    GeForce RTX™ 3060 Ti VISION OC 8G (rev. 2.0)
    Sound Card
    "Realtek USB Audio", ROG SupremeFX 7.1 Surround Sound High Definition Audio CODEC ALC4080, Bose Computer Music Monitor/ Desktop Computer Speakers
    Monitor(s) Displays
    Dell S3221QS
    Screen Resolution
    4K but I usually display at 1K
    Hard Drives
    Sam 980 Pro 1T M.2, 990Pro, WD 570, others(all NVMe)
    PSU
    Corsair RM750e fully modular
    Case
    CoolerMaster TD500 mesh white case
    Cooling
    CPU:Thermalright aio A-E-360 V4 TOP(Thermalright anti-bend plate), CASE:3 front fans IN, 1 back fan OUT.
    Keyboard
    Corsair K55 Core RGB
    Mouse
    Corsair Harpoon RGB wireless
    Internet Speed
    220Mbs Starry I226-V
    Browser
    Firefox current, Tab center Reborn, etc etc etc.
    Antivirus
    BitDefender AV Free
    Other Info
    WuMgr, StartAllBack, Terabyte Image for Win, Revo Uninstaller Pro Portable.
    Time Spy Extreme 6239, VRMark Orange Room 16430, etc.
    Been doing computers since '62(IBM 7070/4(just missed their 650!!!). Managed a bunch of 360's. My first PC I think was one of the RS puters (I tried them all), a commodore, an IBM PC w DOS 3.11, and others mainly DIY (COMPUTER SHOPPER!!!) w 95, 98, xp, vista, me, 7!!!, 8, 10!!!, 11.
    I use Wondershare Filmora Basic to process my vlogs. Pocket 2
  • Operating System
    win 10, Mint
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo P15s
    CPU
    i7-10510U 1.8-4.9GHz
    Motherboard
    Intel SoC
    Memory
    16GB DDR4
    Graphics card(s)
    Nvidia Quadro P520 2GB DDR5 supports 4K external via HDMI or USB-C
    Sound Card
    Realtek ALC3287 HD
    Monitor(s) Displays
    15.6"
    Screen Resolution
    1K
    Hard Drives
    NVMe various
Thats fast! But a bit of diffrence situation. Only in disaster/recovery i tend to move my ass from my chair to do things on that systems. All must be remote, with no downtimes.
 
Last edited:

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
Yes, it is not quite so spritely under win: starts out fast but often drops down to 500 for most of it. Terabyte had no idea why. It might be heat but I don't think so -

These are on mobo NVMe's Sammy 980Pro to 990Pro.


Screenshot 2025-02-15 162858.webpScreenshot 2025-02-15 163104.webpScreenshot 2025-02-15 163137.webp
 

My Computers

System One System Two

  • OS
    win 11Pro, 24H2, 26100.3194
    Computer type
    PC/Desktop
    Manufacturer/Model
    DIY
    CPU
    I9-13900k
    Motherboard
    ASUS ROG STRIX Z790-E Gam wifi-6E, latest AMI BIOS 2801
    Memory
    G.Skill Ripjaws S5 32GB Kit DDR5 6000. 6000.
    Graphics Card(s)
    GeForce RTX™ 3060 Ti VISION OC 8G (rev. 2.0)
    Sound Card
    "Realtek USB Audio", ROG SupremeFX 7.1 Surround Sound High Definition Audio CODEC ALC4080, Bose Computer Music Monitor/ Desktop Computer Speakers
    Monitor(s) Displays
    Dell S3221QS
    Screen Resolution
    4K but I usually display at 1K
    Hard Drives
    Sam 980 Pro 1T M.2, 990Pro, WD 570, others(all NVMe)
    PSU
    Corsair RM750e fully modular
    Case
    CoolerMaster TD500 mesh white case
    Cooling
    CPU:Thermalright aio A-E-360 V4 TOP(Thermalright anti-bend plate), CASE:3 front fans IN, 1 back fan OUT.
    Keyboard
    Corsair K55 Core RGB
    Mouse
    Corsair Harpoon RGB wireless
    Internet Speed
    220Mbs Starry I226-V
    Browser
    Firefox current, Tab center Reborn, etc etc etc.
    Antivirus
    BitDefender AV Free
    Other Info
    WuMgr, StartAllBack, Terabyte Image for Win, Revo Uninstaller Pro Portable.
    Time Spy Extreme 6239, VRMark Orange Room 16430, etc.
    Been doing computers since '62(IBM 7070/4(just missed their 650!!!). Managed a bunch of 360's. My first PC I think was one of the RS puters (I tried them all), a commodore, an IBM PC w DOS 3.11, and others mainly DIY (COMPUTER SHOPPER!!!) w 95, 98, xp, vista, me, 7!!!, 8, 10!!!, 11.
    I use Wondershare Filmora Basic to process my vlogs. Pocket 2
  • Operating System
    win 10, Mint
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo P15s
    CPU
    i7-10510U 1.8-4.9GHz
    Motherboard
    Intel SoC
    Memory
    16GB DDR4
    Graphics card(s)
    Nvidia Quadro P520 2GB DDR5 supports 4K external via HDMI or USB-C
    Sound Card
    Realtek ALC3287 HD
    Monitor(s) Displays
    15.6"
    Screen Resolution
    1K
    Hard Drives
    NVMe various
BTW if you have 10,000 computers and never restart them, you should. Win is much better after a restart!!!

In the same breath: if you never rebuild your computers, you should every year or 2. Win is much nicer after a rebuild!
 

My Computers

System One System Two

  • OS
    win 11Pro, 24H2, 26100.3194
    Computer type
    PC/Desktop
    Manufacturer/Model
    DIY
    CPU
    I9-13900k
    Motherboard
    ASUS ROG STRIX Z790-E Gam wifi-6E, latest AMI BIOS 2801
    Memory
    G.Skill Ripjaws S5 32GB Kit DDR5 6000. 6000.
    Graphics Card(s)
    GeForce RTX™ 3060 Ti VISION OC 8G (rev. 2.0)
    Sound Card
    "Realtek USB Audio", ROG SupremeFX 7.1 Surround Sound High Definition Audio CODEC ALC4080, Bose Computer Music Monitor/ Desktop Computer Speakers
    Monitor(s) Displays
    Dell S3221QS
    Screen Resolution
    4K but I usually display at 1K
    Hard Drives
    Sam 980 Pro 1T M.2, 990Pro, WD 570, others(all NVMe)
    PSU
    Corsair RM750e fully modular
    Case
    CoolerMaster TD500 mesh white case
    Cooling
    CPU:Thermalright aio A-E-360 V4 TOP(Thermalright anti-bend plate), CASE:3 front fans IN, 1 back fan OUT.
    Keyboard
    Corsair K55 Core RGB
    Mouse
    Corsair Harpoon RGB wireless
    Internet Speed
    220Mbs Starry I226-V
    Browser
    Firefox current, Tab center Reborn, etc etc etc.
    Antivirus
    BitDefender AV Free
    Other Info
    WuMgr, StartAllBack, Terabyte Image for Win, Revo Uninstaller Pro Portable.
    Time Spy Extreme 6239, VRMark Orange Room 16430, etc.
    Been doing computers since '62(IBM 7070/4(just missed their 650!!!). Managed a bunch of 360's. My first PC I think was one of the RS puters (I tried them all), a commodore, an IBM PC w DOS 3.11, and others mainly DIY (COMPUTER SHOPPER!!!) w 95, 98, xp, vista, me, 7!!!, 8, 10!!!, 11.
    I use Wondershare Filmora Basic to process my vlogs. Pocket 2
  • Operating System
    win 10, Mint
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo P15s
    CPU
    i7-10510U 1.8-4.9GHz
    Motherboard
    Intel SoC
    Memory
    16GB DDR4
    Graphics card(s)
    Nvidia Quadro P520 2GB DDR5 supports 4K external via HDMI or USB-C
    Sound Card
    Realtek ALC3287 HD
    Monitor(s) Displays
    15.6"
    Screen Resolution
    1K
    Hard Drives
    NVMe various
Restarts happens during maintaince hours after windows updates. Well if systems are maintained good enough, they can run longer. We have still one windows 2000 server running, that was first a phyical machine, then later converted to virtual machine, that has a intranet website running on it, that was custom build, costed over 100.000euro during that time. Dev past away soon after, no manual, no install software, and they still wants to use it.... So it runs local in vmware, and kept it running over the years. Soon will be running over 25years.. Workstation we do tend to reinstall more often, servers not so much, only if it really has issues.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
certainly a very dangerous situation. That happened to a bank I worked for. They eventually found out all those necessary old pgms were embezzling lots. But you are aware.
 

My Computers

System One System Two

  • OS
    win 11Pro, 24H2, 26100.3194
    Computer type
    PC/Desktop
    Manufacturer/Model
    DIY
    CPU
    I9-13900k
    Motherboard
    ASUS ROG STRIX Z790-E Gam wifi-6E, latest AMI BIOS 2801
    Memory
    G.Skill Ripjaws S5 32GB Kit DDR5 6000. 6000.
    Graphics Card(s)
    GeForce RTX™ 3060 Ti VISION OC 8G (rev. 2.0)
    Sound Card
    "Realtek USB Audio", ROG SupremeFX 7.1 Surround Sound High Definition Audio CODEC ALC4080, Bose Computer Music Monitor/ Desktop Computer Speakers
    Monitor(s) Displays
    Dell S3221QS
    Screen Resolution
    4K but I usually display at 1K
    Hard Drives
    Sam 980 Pro 1T M.2, 990Pro, WD 570, others(all NVMe)
    PSU
    Corsair RM750e fully modular
    Case
    CoolerMaster TD500 mesh white case
    Cooling
    CPU:Thermalright aio A-E-360 V4 TOP(Thermalright anti-bend plate), CASE:3 front fans IN, 1 back fan OUT.
    Keyboard
    Corsair K55 Core RGB
    Mouse
    Corsair Harpoon RGB wireless
    Internet Speed
    220Mbs Starry I226-V
    Browser
    Firefox current, Tab center Reborn, etc etc etc.
    Antivirus
    BitDefender AV Free
    Other Info
    WuMgr, StartAllBack, Terabyte Image for Win, Revo Uninstaller Pro Portable.
    Time Spy Extreme 6239, VRMark Orange Room 16430, etc.
    Been doing computers since '62(IBM 7070/4(just missed their 650!!!). Managed a bunch of 360's. My first PC I think was one of the RS puters (I tried them all), a commodore, an IBM PC w DOS 3.11, and others mainly DIY (COMPUTER SHOPPER!!!) w 95, 98, xp, vista, me, 7!!!, 8, 10!!!, 11.
    I use Wondershare Filmora Basic to process my vlogs. Pocket 2
  • Operating System
    win 10, Mint
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo P15s
    CPU
    i7-10510U 1.8-4.9GHz
    Motherboard
    Intel SoC
    Memory
    16GB DDR4
    Graphics card(s)
    Nvidia Quadro P520 2GB DDR5 supports 4K external via HDMI or USB-C
    Sound Card
    Realtek ALC3287 HD
    Monitor(s) Displays
    15.6"
    Screen Resolution
    1K
    Hard Drives
    NVMe various
do an occasional defrag.even on an ssd. I alternate between Ultra and defraggler. Does make things cleaner/faster.

That's obviously destructive (shortens lifespan faster than any usual activity - maybe even the stress of 6 months experienced in 1 defrag), but if you're actively monitoring the state of the SSD and afford to replace it (quite cheap this days - compared to the Premium prices from a decade ago), sure... it does help. Not like HDD tho, that's purely coincidental. With HDD - which relies on hardware parts moving around the surface of the rotating disks - to read/write the data - it helps to be rearranged in a way that's easier to access/read/write. SSD on the other hand - doesn't have that issue (since there's no moving parts - the data can be accessed directly at all times), but it does suffer from an issue specific to SSD tech - labeled as Read Disturb Errors:

"Read disturb refers to a phenomenon where the repeated reading of data in an SSD without writing new data can eventually cause bit errors and data corruption (Li et al., 2020). The high-voltage read operations in NAND flash memory can inadvertently bias the voltage levels of adjacent cells over time. This causes electron traps to form in the oxide layer and leads to incorrect readings of the stored voltage levels, essentially flipping bits from 1s to 0s or vice versa.


According to research by Delkin Devices, read disturb happens because “NAND flash memory stores data by trapping electrons on a floating gate. Applying voltage to the floating gate enables reads and writes. With read commands, voltage is applied to the gates of both selected and unselected cells. Eventually, the applied voltage can alter the amount of trapped electrons in unselected cells – changing cell values from a 1 to a 0 or vice versa.”


Thus, frequent SSD read operations without intervening write operations to refresh the data can eventually cause bit errors (Gerofi et al., 2020). SSD controllers attempt to mitigate this issue through read reclaim/refresh operations that rewrite data after a certain number of reads. However, read disturb still contributes to progressive SSD failures, especially for files that are frequently read but rarely updated."

That being said and taking into account the way defragmention works - the re-allocation/write process will actually "refresh the data" - which again, coincidentally fits with the research on countering Data Disturb Errors:


So again, coincidentally - you can achieve similar "performance improvements (at the cost of lifespan)" while running a - Full "Read+Write+Read Test (which will "refresh" the data by design)" with an app like Hard Disk Sentinel - even tho, this function was intended for HDD.
 

My Computer

System One

  • OS
    WinDOS 23H2
    Computer type
    Laptop
    CPU
    Intel & AMD
    Memory
    SO-DIMM SK Hynix 15.8 GB Dual-Channel DDR4-2666 (2 x 8 GB) 1329MHz (19-19-19-43)
    Graphics Card(s)
    nVidia RTX 2060 6GB Mobile GPU (TU106M)
    Sound Card
    Onbord Realtek ALC1220
    Screen Resolution
    1920 x 1080
    Hard Drives
    1x Samsung PM981 NVMe PCIe M.2 512GB / 1x Seagate Expansion ST1000LM035 1TB
New version:

Added: -Verbose option
Bug: if 0 files detected, this was not shown, adjusted the message.


Powershell:
# Save as WinSxSDeleteEmptyInFlightFolders.ps1
# Run with .\WinSxSDeleteEmptyInFlightFolders.ps1
# To See the all output in the console, run with .\WinSxSDeleteEmptyInFlightFolders.ps1 -Verbose
# Report issus with this script at: https://www.elevenforum.com/t/c-windows-winsxs-temp-inflight-deleting-empty-folders.33434/
# Version 0.5
param(
    [switch]
    $Verbose
)

  function Invoke-WinSxSDeleteEmptyInFlightFolders {
    begin {
        #region Enable Privilege function
        function Enable-Privilege {
            param(
                ## The privilege to adjust. This set is taken from
                ## http://msdn.microsoft.com/en-us/library/bb530716(VS.85).aspx
                [ValidateSet(
                    "SeAssignPrimaryTokenPrivilege", "SeAuditPrivilege", "SeBackupPrivilege",
                    "SeChangeNotifyPrivilege", "SeCreateGlobalPrivilege", "SeCreatePagefilePrivilege",
                    "SeCreatePermanentPrivilege", "SeCreateSymbolicLinkPrivilege", "SeCreateTokenPrivilege",
                    "SeDebugPrivilege", "SeEnableDelegationPrivilege", "SeImpersonatePrivilege", "SeIncreaseBasePriorityPrivilege",
                    "SeIncreaseQuotaPrivilege", "SeIncreaseWorkingSetPrivilege", "SeLoadDriverPrivilege",
                    "SeLockMemoryPrivilege", "SeMachineAccountPrivilege", "SeManageVolumePrivilege",
                    "SeProfileSingleProcessPrivilege", "SeRelabelPrivilege", "SeRemoteShutdownPrivilege",
                    "SeRestorePrivilege", "SeSecurityPrivilege", "SeShutdownPrivilege", "SeSyncAgentPrivilege",
                    "SeSystemEnvironmentPrivilege", "SeSystemProfilePrivilege", "SeSystemtimePrivilege",
                    "SeTakeOwnershipPrivilege", "SeTcbPrivilege", "SeTimeZonePrivilege", "SeTrustedCredManAccessPrivilege",
                    "SeUndockPrivilege", "SeUnsolicitedInputPrivilege")]
                $Privilege,
                ## The process on which to adjust the privilege. Defaults to the current process.
                $ProcessId = $pid,
                ## Switch to disable the privilege, rather than enable it.
                [Switch] $Disable
            )
    
            ## Taken from P/Invoke.NET with minor adjustments.
            $definition = @'
using System;
using System.Runtime.InteropServices;
 
public class AdjPriv
{
    [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
    internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
    ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);
 
    [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
    internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);
    [DllImport("advapi32.dll", SetLastError = true)]
    internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    internal struct TokPriv1Luid
    {
    public int Count;
    public long Luid;
    public int Attr;
    }
 
    internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
    internal const int SE_PRIVILEGE_DISABLED = 0x00000000;
    internal const int TOKEN_QUERY = 0x00000008;
    internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
    public static bool EnablePrivilege(long processHandle, string privilege, bool disable)
    {
        bool retVal;
        TokPriv1Luid tp;
        IntPtr hproc = new IntPtr(processHandle);
        IntPtr htok = IntPtr.Zero;
        retVal = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
        if (!retVal) return false;
        tp.Count = 1;
        tp.Luid = 0;
        tp.Attr = disable ? SE_PRIVILEGE_DISABLED : SE_PRIVILEGE_ENABLED;
        retVal = LookupPrivilegeValue(null, privilege, ref tp.Luid);
        if (!retVal) return false;
        retVal = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
        return retVal;
    }
}
'@
    
            $processHandle = (Get-Process -id $ProcessId).Handle
            $typeexists = try { ([AdjPriv] -is [type]); $true } catch { $false }
            if ( $typeexists -eq $false ) {
                $type = Add-Type $definition -PassThru
            }
            $result = [AdjPriv]::EnablePrivilege($processHandle, $Privilege, $Disable)
            if (-not $result) {
                $errorCode = [System.Runtime.InteropServices.Marshal]::GetLastWin32Error()
                throw "Failed to change privilege '$Privilege'. Error code: $errorCode."
            }
        }
        #endregion Enable Privilege function
    }

process {
    try {
        # Check for Admin rights
        if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")) {
            Write-Warning "Must be run with administrator credentials"
            return
        }

        try {
            # Add SeTakeOwnershipPrivilege and SeRestorePrivilege for this process
            Enable-Privilege -Privilege SeTakeOwnershipPrivilege
            Enable-Privilege -Privilege SeRestorePrivilege
        }
        catch {
            Write-Error $_.Exception.Message
            return
        }
        
        $totalDeletedFolderCount = 0
        
        do {
            # Find empty folders
            $emptyFolders = Get-ChildItem -Path $env:windir\WinSxS\Temp\InFlight -Recurse -Directory | Where-Object { (Get-ChildItem -Path $_.FullName -Force).Count -eq 0 }

            # If no empty folders are found, exit the loop
            if ($emptyFolders.Count -eq 0) {
                break
            }

            # Initialize a counter for deleted folders in THIS ITERATION
            $deletedFolderCount = 0

            $NTAccount_Administrators = [System.Security.Principal.NTAccount]"Administrators"

            foreach ($emptyInFlightFolder In $emptyFolders) {
                #region Change ownership of the root folder
                try {
                    $acl = Get-Acl -Path $emptyInFlightFolder.FullName
                    $acl.SetOwner($NTAccount_Administrators)
                    Set-Acl -Path $emptyInFlightFolder.FullName -AclObject $acl
                    Write-Host "Changed owner on '$($emptyInFlightFolder.FullName)' to '$($NTAccount_Administrators)'..."
                }
                catch {
                    Write-Warning "Failed to change owner on folder $($emptyInFlightFolder.FullName). Error: $($_.Exception.Message)"
                    continue # Skip to the next folder if ownership change fails
                }
                #endregion

                #region Add Administrators Full Control on the folder
                try {
                    $acl = Get-Acl -Path $emptyInFlightFolder.FullName
                    $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule ($NTAccount_Administrators, [System.Security.AccessControl.FileSystemRights]::FullControl, @("ObjectInherit", "ContainerInherit"), "None", "Allow")
                    $acl.AddAccessRule($accessRule)
                    Set-Acl -Path $emptyInFlightFolder.FullName -AclObject $acl
                    if ($Verbose) { Write-Host "[Folder] Added Administrators with full control on '$($emptyInFlightFolder.FullName)' to '$($NTAccount_Administrators)'..." -ForegroundColor Cyan }
                }
                catch {
                    Write-Warning "Failed to add full control permissions to folder $($emptyInFlightFolder.FullName). Error: $($_.Exception.Message)"
                    continue # Skip to the next folder if adding permissions fails
                }
                #endregion

                # Attempt to remove the folder
                try {
                    Remove-Item -Path "$($emptyInFlightFolder.FullName)" -Recurse -Force -Confirm:$false
                    $deletedFolderCount++ # Increment the counter if deletion is successful
                    if ($Verbose) { Write-Host "Successfully deleted folder: $($emptyInFlightFolder.FullName)" }
                }
                catch {
                    Write-Warning "Failed to delete folder $($emptyInFlightFolder.FullName). Error: $($_.Exception.Message)"
                }
            }
            # Add the number of folders deleted in this iteration to the total
            $totalDeletedFolderCount += $deletedFolderCount
        } while ($true) # Infinite loop that breaks when no empty folders are found
        if ($totalDeletedFolderCount -eq 0) {
            Write-Host "No empty folders were found."
        } else {
            Write-Host "Total empty folders deleted across all iterations: $totalDeletedFolderCount"  # Display total at the end
        }
    }
    catch {
        Write-Host "An error occurred: $($_.Exception.Message)" -ForegroundColor Red
        throw $_
    }
}

end {}
}

Invoke-Command -ScriptBlock { Invoke-WinSxSDeleteEmptyInFlightFolders }
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
Since you're releasing the other script (and may find even more folder instances):
1. Move the Enable-Privilege function out of Invoke-* function (making it global to the script). This will improve the script's readability.

2. Pass a param for the root folder $path, so you make this function generic for any other random empty folder locations (that don't meet some naming restriction).
 

My Computer

System One

  • OS
    Windows 7
Good idea's i might do that later, for these standalone versions.
Now working on a version that integrates it with our own maintance scripts and outputs it in our logfiles, that we can read from central point where we collect the logs, and can see the errors from all the machines. So for there i have made a new function for the Enable Privilege , so it is not intergated 3times in each code for the cleanup scripts, and can be used for other scripts. We already had a function that used takeown & icacls, so making a todolist to replace that with this new code. Hope that will bring down some running script times aswell.
For my own application i use at home, converted it into a c# code, so i can use AdjPriv directly instead of calling takeown & icalcs or run a powershell script in the background of the application doing such operations. Lots of things on the todo list now!

Thanks!
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
That's obviously destructive (shortens lifespan faster than any usual activity - maybe even the stress of 6 months experienced in 1 defrag), but if you're actively monitoring the ... ,snip.
LOL!!!
Okay so that's the obligatory "don't". However:

I pretty much only buy Samsung NVMe's and I defrag them occasionally because
1) I have found that it helps
2) I have NEVER had a sammy go bad.

I would pretty much never do that to a non-sammy stick.

of course YMMV.
:D
 
Last edited:

My Computers

System One System Two

  • OS
    win 11Pro, 24H2, 26100.3194
    Computer type
    PC/Desktop
    Manufacturer/Model
    DIY
    CPU
    I9-13900k
    Motherboard
    ASUS ROG STRIX Z790-E Gam wifi-6E, latest AMI BIOS 2801
    Memory
    G.Skill Ripjaws S5 32GB Kit DDR5 6000. 6000.
    Graphics Card(s)
    GeForce RTX™ 3060 Ti VISION OC 8G (rev. 2.0)
    Sound Card
    "Realtek USB Audio", ROG SupremeFX 7.1 Surround Sound High Definition Audio CODEC ALC4080, Bose Computer Music Monitor/ Desktop Computer Speakers
    Monitor(s) Displays
    Dell S3221QS
    Screen Resolution
    4K but I usually display at 1K
    Hard Drives
    Sam 980 Pro 1T M.2, 990Pro, WD 570, others(all NVMe)
    PSU
    Corsair RM750e fully modular
    Case
    CoolerMaster TD500 mesh white case
    Cooling
    CPU:Thermalright aio A-E-360 V4 TOP(Thermalright anti-bend plate), CASE:3 front fans IN, 1 back fan OUT.
    Keyboard
    Corsair K55 Core RGB
    Mouse
    Corsair Harpoon RGB wireless
    Internet Speed
    220Mbs Starry I226-V
    Browser
    Firefox current, Tab center Reborn, etc etc etc.
    Antivirus
    BitDefender AV Free
    Other Info
    WuMgr, StartAllBack, Terabyte Image for Win, Revo Uninstaller Pro Portable.
    Time Spy Extreme 6239, VRMark Orange Room 16430, etc.
    Been doing computers since '62(IBM 7070/4(just missed their 650!!!). Managed a bunch of 360's. My first PC I think was one of the RS puters (I tried them all), a commodore, an IBM PC w DOS 3.11, and others mainly DIY (COMPUTER SHOPPER!!!) w 95, 98, xp, vista, me, 7!!!, 8, 10!!!, 11.
    I use Wondershare Filmora Basic to process my vlogs. Pocket 2
  • Operating System
    win 10, Mint
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo P15s
    CPU
    i7-10510U 1.8-4.9GHz
    Motherboard
    Intel SoC
    Memory
    16GB DDR4
    Graphics card(s)
    Nvidia Quadro P520 2GB DDR5 supports 4K external via HDMI or USB-C
    Sound Card
    Realtek ALC3287 HD
    Monitor(s) Displays
    15.6"
    Screen Resolution
    1K
    Hard Drives
    NVMe various
Do you really defrag them? Or do you Trim them?
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
@garlin For me defrag.exe does the retrim on ssd's. For me disk cleanup does not defrag the disk. Your AI hallucinating?
Edit: ah you deleted your reply.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
Do you really defrag them? Or do you Trim them?
Both of these are an excellent issue and should be looked at and understood by all!!!!!

The built in "defragger"(CP/WindowsTools/Defragment optimize..).: I set that to defrag once a week. It senses that these are SSDs and trims them, SO ONE HUGE PROBLEM TAKEN CARE OF!!!!!!!!!!! - imho SSDs should be trimmed on a regular basis!!!

Occasionally, when I gut feel think it needs it, perhaps once every 2 months, I will grab something like defraggler or Ultradefrag or the like and run an analyze. Depending on what it says I will do a defrag or one of the other choices.

So a huge YES to both, and I feel folks aren't aware, and their SSDs would be a lot healthier if they would learn and attend!!!

You get 10 points for excellent question!!!
EDIT: 20 points because I just looked at it and discovered that the schedule wasn't on, so set it to 1wk and ran optimize on each one. It is so quick - takes maybe 1 sec. So THANKS!!!!!!!!!
 

My Computers

System One System Two

  • OS
    win 11Pro, 24H2, 26100.3194
    Computer type
    PC/Desktop
    Manufacturer/Model
    DIY
    CPU
    I9-13900k
    Motherboard
    ASUS ROG STRIX Z790-E Gam wifi-6E, latest AMI BIOS 2801
    Memory
    G.Skill Ripjaws S5 32GB Kit DDR5 6000. 6000.
    Graphics Card(s)
    GeForce RTX™ 3060 Ti VISION OC 8G (rev. 2.0)
    Sound Card
    "Realtek USB Audio", ROG SupremeFX 7.1 Surround Sound High Definition Audio CODEC ALC4080, Bose Computer Music Monitor/ Desktop Computer Speakers
    Monitor(s) Displays
    Dell S3221QS
    Screen Resolution
    4K but I usually display at 1K
    Hard Drives
    Sam 980 Pro 1T M.2, 990Pro, WD 570, others(all NVMe)
    PSU
    Corsair RM750e fully modular
    Case
    CoolerMaster TD500 mesh white case
    Cooling
    CPU:Thermalright aio A-E-360 V4 TOP(Thermalright anti-bend plate), CASE:3 front fans IN, 1 back fan OUT.
    Keyboard
    Corsair K55 Core RGB
    Mouse
    Corsair Harpoon RGB wireless
    Internet Speed
    220Mbs Starry I226-V
    Browser
    Firefox current, Tab center Reborn, etc etc etc.
    Antivirus
    BitDefender AV Free
    Other Info
    WuMgr, StartAllBack, Terabyte Image for Win, Revo Uninstaller Pro Portable.
    Time Spy Extreme 6239, VRMark Orange Room 16430, etc.
    Been doing computers since '62(IBM 7070/4(just missed their 650!!!). Managed a bunch of 360's. My first PC I think was one of the RS puters (I tried them all), a commodore, an IBM PC w DOS 3.11, and others mainly DIY (COMPUTER SHOPPER!!!) w 95, 98, xp, vista, me, 7!!!, 8, 10!!!, 11.
    I use Wondershare Filmora Basic to process my vlogs. Pocket 2
  • Operating System
    win 10, Mint
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo P15s
    CPU
    i7-10510U 1.8-4.9GHz
    Motherboard
    Intel SoC
    Memory
    16GB DDR4
    Graphics card(s)
    Nvidia Quadro P520 2GB DDR5 supports 4K external via HDMI or USB-C
    Sound Card
    Realtek ALC3287 HD
    Monitor(s) Displays
    15.6"
    Screen Resolution
    1K
    Hard Drives
    NVMe various
You get 10 points for excellent question!!!
How many more point do i need for the washing machine? :p
The build in "defragger": I set that to defrag once a week. It senses that these are SSDs and trims them,
Yeah thats the reason why i ask. Some people (not you) get confused with it.

However i do not use defraggler at all on SSD. I do on harddrives.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
You got the machine (2.5") - it'll be delivered tomorrow.!!!
Yes, defraggler is a bit brute force and that is why I keep it around. It will do what others won't. It IS very harsh on a spindle, though I used to do that. I do still have a couple 2.5 spindles but only use SSDs for on and off site backup. So cheap!!! So fast!!!
 

My Computers

System One System Two

  • OS
    win 11Pro, 24H2, 26100.3194
    Computer type
    PC/Desktop
    Manufacturer/Model
    DIY
    CPU
    I9-13900k
    Motherboard
    ASUS ROG STRIX Z790-E Gam wifi-6E, latest AMI BIOS 2801
    Memory
    G.Skill Ripjaws S5 32GB Kit DDR5 6000. 6000.
    Graphics Card(s)
    GeForce RTX™ 3060 Ti VISION OC 8G (rev. 2.0)
    Sound Card
    "Realtek USB Audio", ROG SupremeFX 7.1 Surround Sound High Definition Audio CODEC ALC4080, Bose Computer Music Monitor/ Desktop Computer Speakers
    Monitor(s) Displays
    Dell S3221QS
    Screen Resolution
    4K but I usually display at 1K
    Hard Drives
    Sam 980 Pro 1T M.2, 990Pro, WD 570, others(all NVMe)
    PSU
    Corsair RM750e fully modular
    Case
    CoolerMaster TD500 mesh white case
    Cooling
    CPU:Thermalright aio A-E-360 V4 TOP(Thermalright anti-bend plate), CASE:3 front fans IN, 1 back fan OUT.
    Keyboard
    Corsair K55 Core RGB
    Mouse
    Corsair Harpoon RGB wireless
    Internet Speed
    220Mbs Starry I226-V
    Browser
    Firefox current, Tab center Reborn, etc etc etc.
    Antivirus
    BitDefender AV Free
    Other Info
    WuMgr, StartAllBack, Terabyte Image for Win, Revo Uninstaller Pro Portable.
    Time Spy Extreme 6239, VRMark Orange Room 16430, etc.
    Been doing computers since '62(IBM 7070/4(just missed their 650!!!). Managed a bunch of 360's. My first PC I think was one of the RS puters (I tried them all), a commodore, an IBM PC w DOS 3.11, and others mainly DIY (COMPUTER SHOPPER!!!) w 95, 98, xp, vista, me, 7!!!, 8, 10!!!, 11.
    I use Wondershare Filmora Basic to process my vlogs. Pocket 2
  • Operating System
    win 10, Mint
    Computer type
    Laptop
    Manufacturer/Model
    Lenovo P15s
    CPU
    i7-10510U 1.8-4.9GHz
    Motherboard
    Intel SoC
    Memory
    16GB DDR4
    Graphics card(s)
    Nvidia Quadro P520 2GB DDR5 supports 4K external via HDMI or USB-C
    Sound Card
    Realtek ALC3287 HD
    Monitor(s) Displays
    15.6"
    Screen Resolution
    1K
    Hard Drives
    NVMe various

Latest Support Threads

Back
Top Bottom