PowerShell: logifailide kustutaja: Difference between revisions
From ICO wiki
Jump to navigationJump to search
No edit summary |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
# | |||
# Kustutab kõik failid mis on vanemad kui 30 päeva | |||
param( | param( | ||
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()]$Path, | [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()]$Path, | ||
$DaysBack = 30) | $DaysBack = 30) | ||
$CurrentDate = Get-Date | $CurrentDate = Get-Date | ||
$DatetoDelete = $CurrentDate.AddDays(-$Daysback) | $DatetoDelete = $CurrentDate.AddDays(-$Daysback) | ||
if($Path -ne ""){ | if($Path -ne ""){ | ||
Get-ChildItem $Path | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item | Get-ChildItem $Path | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item | ||
} | } |
Latest revision as of 15:49, 22 May 2012
- Kustutab kõik failid mis on vanemad kui 30 päeva
param(
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()]$Path,
$DaysBack = 30)
$CurrentDate = Get-Date
$DatetoDelete = $CurrentDate.AddDays(-$Daysback)
if($Path -ne ""){
Get-ChildItem $Path | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item
}