Мониторинг устаревших файлов

function funline ($strIN)
{
 $num = $strIN.length
 for($i=1 ; $i -le $num ; $i++)
  { $funline = $funline + "=" }
    Write-Host -ForegroundColor yellow $strIN 
    Write-Host -ForegroundColor darkYellow $funline
}

$folder = "c:\fso"
$date = Get-Date
$limit = 30

Get-ChildItem -Path $folder -force |
foreach-object `
{ 
 $newDate=($_.LastAccessTime).adddays($limit) 
 $limitDate = New-TimeSpan -start $date -end $newDate

 if ($limitDate -le 0) 
  { 
   $xfiles += @{ $_.name = $_.lastAccessTime }
  }
    
}
Write-Host "There are $($xfiles.count) files from $folder greater than $limit days old."
FunLine("The expired files are listed below:")

$xfiles
0
Голосов пока нет

Оставить комментарий