# Avant
function Remove-OldFiles {
    [CmdletBinding()]
    param(
        [Parameter(
            Mandatory=$true
            )]
        [string]$Path,

        [Parameter(
            Mandatory=$true
        )]
        [int]$Day,

        [Parameter(
            Mandatory=$false
        )]
        [switch]$Recurse
    )
    process {
        $Now = Get-Date
        $Limit = $Now.AddDays(-$Day)
        
        Get-ChildItem -Path $Path -Recurse:$Recurse -File |
            Where-Object { $_.LastWriteTime -lt $Limit } |
            Remove-Item -Force -Recurse
    }
}

# Apres
function Remove-OldFiles {
    [CmdletBinding()]
    param(
        [Parameter(
            Mandatory=$true
            )]
        [ValidateScript({ Test-Path -Path $_ -Leaf })]
        [ValidateDrive('C','D')]
        [string]$Path,

        [Parameter(
            Mandatory=$true
        )]
        [ValidateRange(30,365)]
        [int]$Day,

        [Parameter(Mandatory=$false, Position=2)]
        [switch]$Recurse
    )
    process {
        $Now = Get-Date
        $Limit = $Now.AddDays(-$Day)
        
        Get-ChildItem -Path $Path -Recurse:$Recurse -File |
            Where-Object { $_.LastWriteTime -lt $Limit } |
            Remove-Item -Force -Recurse
    }
}


<#
Version              Name                                Repository
-------              ----                                ----------
9.0.0                NetworkingDsc                       PSGallery
9.0.0                ComputerManagementDsc               PSGallery
3.2.0.0              xCertificate                        PSGallery
5.1.0                CertificateDsc                      PSGallery
2.12.0.0             PSDscResources                      PSGallery
3.1.1                WSManDsc                            PSGallery
3.3.0                xWebAdministration                  PSGallery
3.1.0.0              xPowerShellExecutionPolicy          PSGallery
9.1.0                xPSDesiredStateConfiguration        PSGallery
16.3.1               SqlServerDsc                        PSGallery
2.8.0.0              xWindowsUpdate                      PSGallery
1.2.0.0              SystemLocaleDsc                     PSGallery
6.2.0                ActiveDirectoryDsc                  PSGallery
2.0.0                xDnsServer                          PSGallery
5.7.0.0              xNetworking                         PSGallery
1.4.0.0              AuditPolicyDsc                      PSGallery
2.10.0.0             SecurityPolicyDsc                   PSGallery
2.0.0.15             ReverseDSC                          PSGallery
1.3.0.151            FileContentDsc                      PSGallery
1.2.0                GPRegistryPolicyDsc                 PSGallery
2.2.0                WindowsDefenderDsc                  PSGallery
1.1.0                AuditSystemDsc                      PSGallery
1.4.3                AccessControlDSC                    PSGallery
1.23.517.1           Microsoft365DSC                     PSGallery
1.16.1               xFailOverCluster                    PSGallery
3.4.0.0              xStorage                            PSGallery
0.16.2               DscResource.Test                    PSGallery
2.2.0.0              xSmbShare                           PSGallery
4.1.0.0              xComputerManagement                 PSGallery
3.0.0.0              xActiveDirectory                    PSGallery
4.1.0                WebAdministrationDsc                PSGallery
0.4.0.0              xPendingReboot                      PSGallery
2.1.0                xRemoteDesktopSessionHost           PSGallery
5.1.0                StorageDsc                          PSGallery
1.8.0.0              xTimeZone                           PSGallery
1.5.1                xSystemSecurity                     PSGallery
#>