← Каталог
Стандартные блоки и модули PowerShell — Пример — файлы старше N дней
Фрагмент из «Стандартные блоки и модули PowerShell»: Пример — файлы старше N дней.
function Get-FilesOlderThan {
[CmdletBinding()]
[OutputType([System.IO.FileInfo[]])]
param(
[Parameter(Mandatory)]
[string]$Path,
[Parameter(Mandatory)]
[ValidateRange(1, [int]::MaxValue)]
[int]$Days
)
$cutoff = (Get-Date).AddDays(-$Days)
Get-ChildItem -LiteralPath $Path -File |
Where-Object { $_.LastWriteTime -lt $cutoff }
} function Get-FilesOlderThan {
[CmdletBinding()]
[OutputType([System.IO.FileInfo[]])]
param(
[Parameter(Mandatory)]
[string]$Path,
[Parameter(Mandatory)]
[ValidateRange(1, [int]::MaxValue)]
[int]$Days
)
$cutoff = (Get-Date).AddDays(-$Days)
Get-ChildItem -LiteralPath $Path -File |
Where-Object { $_.LastWriteTime -lt $cutoff }
}