使用PowerShell Runbook从Azure Data Lake商店中删除旧文件

时间:2018-02-09 09:43:48

标签: azure-powershell

有人知道如何在数据湖存储和子目录中的目录中删除超过90天的每个文件吗?

1 个答案:

答案 0 :(得分:0)

这可以使用以下代码实现。请检查并确认您的查询是否已解决。

$PurgeDays = -90
$olddate = (Get-Date).AddDays($PurgeDays)


$year = (Get-Date).AddDays($PurgeDays).Year
$month = (Get-Date).AddDays($PurgeDays).Month
$day = (Get-Date).AddDays($PurgeDays).Day

Write-Output "Files older than $olddate are getting deleted..."

$path = "/MyFolder/$year/$month/$day"

$fileslist = Get-AzureRmDataLakeStoreChildItem -AccountName "MyADLSAccount" -Path $path

if($fileslist)
{
    Remove-AzureRmDataLakeStoreItem -AccountName "MyADLSAccount" -Paths $path -Force -Recurse $true 
    Write-Output "Deleted the folder $path successfully"
}
else
{
    Write-Output "Could not purge the folder $fileslist. Either it is not old or it is not existing."
}