PowerShell: logifailide kustutaja: Difference between revisions

From ICO wiki
Jump to navigationJump to search
Rtetsman (talk | contribs)
No edit summary
Rtetsman (talk | contribs)
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
1
. # SYNOPSIS: Kustutab kõik failide logid, mis on vanemad kui 30 päeva


02
# Kustutab kõik failid mis on vanemad kui 30 päeva
 
 
param(
param(
03
 
     [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()]$Path,
     [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()]$Path,
04
 
     $DaysBack = 30)
     $DaysBack = 30)
05
 
   
   
06
 
$CurrentDate = Get-Date
$CurrentDate = Get-Date
07
 
$DatetoDelete = $CurrentDate.AddDays(-$Daysback)
$DatetoDelete = $CurrentDate.AddDays(-$Daysback)
08
 
   
   
09
 
if($Path -ne ""){
if($Path -ne ""){
10
 
     Get-ChildItem $Path | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item
     Get-ChildItem $Path | Where-Object { $_.LastWriteTime -lt $DatetoDelete } | Remove-Item
11
 
}
}

Latest revision as of 15:49, 22 May 2012

  1. 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

}