Tinus EngOps Wiki

Logo

OpsaC - Operating as PowerShell code

Links

Home

IT-Wiki

PowerShell Blog

PowerShell Index

PowerShell Search

Additional Websites

View my GitHub Profile

View my GitHub Gists

View my Codeberg Page

View my Photo Website

Clear Download

published: August 30, 2016 author: Tinu tags: Folder categories: PowerShell


Temporäre Dateien aus dem Download löschen

<# Remove all PDF-Files older than 4 days #>
function Remove-PdfFiles{
    param($path)
    $function = $($MyInvocation.MyCommand.Name)
    $days = (Get-Date).AddDays(-4)
    Get-ChildItem -Include *.pdf -Path $path -Recurse | Where-Object LastWriteTime -lt $days | % {
        Write-Verbose "$(get-date -f 'yyyy-MM-dd HH:mm:ss') $($function)" -Verbose
        "$(get-date -f 'yyyy-MM-dd HH:mm:ss') Remove-Item $($_.FullName)" | Out-File -FilePath $Logfullname -Encoding default -Append
        Remove-Item -Path $_.FullName -Force 
    }
}

$Scriptpath  = Split-Path -Parent $MyInvocation.MyCommand.Path
$Logfilename = $(($MyInvocation.MyCommand.Name).Replace('ps1','log'))
$Logfullname = "$($Scriptpath)\$($Logfilename)"

Remove-PdfFiles 'C:\Users\<UserName>\Downloads'

← Previous Post ◇ [ Top ] ◇ Copyright © 2024 by tinuwalther ◇ [ Blog ] ◇ Next Post →