• Try something like this. Running it with the -WhatIf will only report what would be deleted by this command. Remove the -WhatIf when you're ready for it to do work.

    #################################################

    #init variables

    $directory = "\\servername\sharename"

    $retentionDate = (Get-Date).AddDays(-2)

    #################################################

    # nothing below here needs to change

    Get-ChildItem $directory |? {($_.PSIsContainer -eq $false) -and ($_.LastWriteTime -lt $retentionDate)} | Remove-Item -WhatIf

    Add -Recurse to the Get-ChildItem call to also delete old files from sub-directories:

    #################################################

    #init variables

    $directory = "\\servername\sharename"

    $retentionDate = (Get-Date).AddDays(-2)

    #################################################

    # nothing below here needs to change

    Get-ChildItem $directory -Recurse |? {($_.PSIsContainer -eq $false) -and ($_.LastWriteTime -lt $retentionDate)} | Remove-Item -WhatIf

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato