LucD,
Please find the script below which i am running.
(
$Servers = @("SWRSVC100"),
$BasePath = "C:\Scripts\Powershell\RVToolsExport\Archive",
$OldFileDays = 30
)
$Date = (Get-Date -f "yyyyMMdd")
foreach ($Server in $Servers)
{
# Create Directory
New-Item -Path "$BasePath\$Server\$Date" -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
# Run Export
. "C:\Program Files (x86)\RobWare\RVTools\RVTools.exe" -passthroughAuth -s "$Server.us.kz.com" -c ExportAll2csv -d "$BasePath\$Server\$Date"
# Cleanup old files
$Items = Get-ChildItem "$path\$server"
foreach ($item in $items)
{
$itemDate = ("{0}/{1}/{2}" -f $item.name.Substring(6,2),$item.name.Substring(4,2),$item.name.Substring(0,4))
if ((((Get-date).AddDays(-$OldFileDays))-(Get-Date($itemDate))).Days -gt 0)
{
$item | Remove-Item -Recurse
}
}
}
thanks
vm2014