Power Shell2009. 12. 15. 21:33
Function DeleteExpireBackupFolder
{
[String]$Date = Get-Date -UFormat "%m%d%y(%H;%M;%S)"

$dirs = dir $BackupFolder

foreach ($folderName in $dirs)
{
[string] $FolderDate = "{0}/{1}/{2}" -f $folderName.ToString().Substring(0,2), $folderName.ToString().Substring(2,2),$folderName.ToString().Substring(4,2)
[string] $NowDate = "{0}/{1}/{2}" -f $Date.ToString().Substring(0,2),$Date.ToString().Substring(2,2),$Date.ToString().Substring(4,2)

$FolderDateToDateTime = [System.DateTime]$FolderDate
$NowDateToDateTime = [System.DateTime]$NowDate
$AddFolderDateToDateTime = $FolderDateToDateTime.AddDays(14)

if($AddFolderDateToDateTime -lt $NowDateToDateTime)
{
Remove-Item $BackupFolder$folderName -Recurse -Force
echo "Deleted $BackupFolder$folderName"
}
}

}


[#FILE|LogBackup.ps1|pds/200912/15/37/|mid|0|0|pds17|0#]


'Power Shell' 카테고리의 다른 글

[ps] 파일 소트 방법  (0) 2009.12.30
[ps] if switch 등 기본문법  (0) 2009.12.15
[ps] 파워셜에서 hashtable쓰기  (0) 2009.12.07
[ps] file copy ,delete 하기  (0) 2009.12.07
[ps] WMI를 통한 Hyper-V 관리...  (0) 2009.12.03
Posted by 동동(이재동)