how to delete fives older than x amount of days

Advertisement

ricedave
Joined:
Posts:
1
Location:
Rich

how to delete fives older than x amount of days

The below Powershell script connects to my SFTP sever and deletes all my files under the path /test/my_file/.

Is there a way where I can say only delete files that is five days old under the path /test/my_file/

Add-Type -Path " WinSCPnet.dll"

$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "example.test.com"
UserName = "username"
Password = "password"
SshHostKeyFingerprint = "ssh-rsa 1234 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
}

$sessionOptions.AddRawSettings("ProxyMethod", "0")
$sessionOptions.AddRawSettings("ProxyHost", "123.45.67.8")
$sessionOptions.AddRawSettings("ProxyPort", "8080")

$session = New-Object WinSCP.Session

try
{
$session.Open($sessionOptions)

# Remove files
$session.RemoveFiles("/test/my_file/*").Check()
}
finally
{
$session.Dispose()
}
thank you in advance.

Reply with quote

Advertisement

Advertisement

You can post new topics in this forum