PowerShell ile log dosyalarini arsivleme (tr-TR)

%3CLINGO-SUB%20id%3D%22lingo-sub-1376297%22%20slang%3D%22en-US%22%3EPowerShell%20ile%20log%20dosyalarini%20arsivleme%20(tr-TR)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1376297%22%20slang%3D%22en-US%22%3E%3CP%3EWindows%20Server%20i%C5%9Fletim%20sistemlerinde%20IIS%2C%20exchange%20gibi%20log%20dosyalar%C4%B1n%C4%B1%20d%C3%BCzenli%20geriye%20d%C3%B6n%C3%BCk%20arsivlemek%20gereken%20hem%20yasal%20olarak%20hemde%20kaynak%20kullan%C4%B1m%C4%B1%20tasarufu%20kapsam%C4%B1nda%20%C3%B6rnek%20scripti%20kullanabilirsiniz.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E7%20g%C3%BCn%20sonra%20geriye%20d%C3%B6n%C3%BCk%20dosylar%C4%B1%20arsivleyen%20scriptdeki%20%24LastWrite%3D(get-date).AddDays(-7).ToString(%22MM%2Fdd%2Fyyyy%22)%207%20de%C4%9Ferini%20de%C4%9Fi%C5%9Ftirerek%20geriye%20d%C3%B6n%C3%BCk%20tutulacak%20arsiv%20g%C3%BCn%20de%C4%9Ferini%20iste%C4%9Finize%20uygun%20g%C3%BCncelleyebilirsiniz.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%C4%B0lgili%20scripti%20task%20scheduler%20%C3%BCzerinde%20yap%C4%B1land%C4%B1rarak%20d%C3%BCzenli%20bir%20%C5%9Fekilde%20kullanabilirsiniz.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24LogFolder%3D%E2%80%9CClog_Dosyasi%E2%80%9D%20%0A%24Arcfolder%3DClogsArsiv_Log_Dosyasi%E2%80%9D%20%0A%24LastWrite%3D(get-date).AddDays(-7).ToString(MMddyyyy)%20%0AIf%20(%24Logs%20%3D%20get-childitem%20%24LogFolder%20%20Where-Object%20%7B%24_.LastWriteTime%20-le%20%24LastWrite%20-and%20!(%24_.PSIsContainer)%7D%20%20sort-object%20LastWriteTime)%20%0A%7B%20%0Aforeach%20(%24L%20in%20%24Logs)%20%0A%7B%20%0A%24FullName%3D%24L.FullName%20%0A%24WMIFileName%3D%20%24FullName.Replace(%2C%20)%20%0A%24WMIQuery%20%3D%20Get-WmiObject%20-Query%20%E2%80%9CSELECT%20%20FROM%20CIM_DataFile%20WHERE%20Name%3D'%24WMIFileName'%E2%80%9C%20%0AIf%20(%24WMIQuery.Compress())%20%7BWrite-Host%20%24FullName%20Arsivleme%20basarili.-ForegroundColor%20Green%7D%20%0Aelse%20%7BWrite-Host%20%24FullName%20Arsivleme%20hatasi.%20-ForegroundColor%20Red%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1376297%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Contributor

Windows Server işletim sistemlerinde IIS, exchange gibi log dosyalarını düzenli geriye dönük arsivlemek gereken hem yasal olarak hemde kaynak kullanımı tasarufu kapsamında örnek scripti kullanabilirsiniz.

 

7 gün sonra geriye dönük dosyları arsivleyen scriptdeki $LastWrite=(get-date).AddDays(-7).ToString("MM/dd/yyyy") 7 değerini değiştirerek geriye dönük tutulacak arsiv gün değerini isteğinize uygun güncelleyebilirsiniz.

 

İlgili scripti task scheduler üzerinde yapılandırarak düzenli bir şekilde kullanabilirsiniz.

 

 

$LogFolder=“Clog_Dosyasi” 
$Arcfolder=ClogsArsiv_Log_Dosyasi” 
$LastWrite=(get-date).AddDays(-7).ToString(MMddyyyy) 
If ($Logs = get-childitem $LogFolder  Where-Object {$_.LastWriteTime -le $LastWrite -and !($_.PSIsContainer)}  sort-object LastWriteTime) 
{ 
foreach ($L in $Logs) 
{ 
$FullName=$L.FullName 
$WMIFileName= $FullName.Replace(, ) 
$WMIQuery = Get-WmiObject -Query “SELECT  FROM CIM_DataFile WHERE Name='$WMIFileName'“ 
If ($WMIQuery.Compress()) {Write-Host $FullName Arsivleme basarili.-ForegroundColor Green} 
else {Write-Host $FullName Arsivleme hatasi. -ForegroundColor Red}

 

 

 

0 Replies