본문 바로가기
OS/Windows

chatgpt code

by 헬로웬디 2025. 3. 3.

Here's the PowerShell script that will run continuously in an infinite loop (while $true) until the user manually stops it.

# Folder path where Procmon logs are stored
$LogPath = "C:\Logs"

# Maximum number of log files to keep
$MaxFiles = 10

# Infinite loop until user intervenes (Ctrl + C or Stop Process)
while ($true) {
    # Get all .PML files sorted by LastWriteTime (oldest first)
    $LogFiles = Get-ChildItem -Path $LogPath -Filter "*.pml" | Sort-Object LastWriteTime

    # Check if the number of files exceeds the limit
    if ($LogFiles.Count -gt $MaxFiles) {
        # Calculate how many files to delete
        $FilesToDelete = $LogFiles.Count - $MaxFiles
        
        # Delete the oldest files
        $LogFiles | Select-Object -First $FilesToDelete | ForEach-Object {
            Write-Host "Deleting file: $($_.FullName)"
            Remove-Item $_.FullName -Force
        }
    }
    else {
        Write-Host "Log files are within the limit. No action needed."
    }
    
    # Wait for 10 seconds before checking again (adjust the delay if needed)
    Start-Sleep -Seconds 10
}

 

'OS > Windows' 카테고리의 다른 글

Windows 부팅 프로세  (0) 2025.03.26
Themida 오류 메시지  (0) 2025.03.05
필터 드라이버(Filter Driver)  (0) 2025.03.03
볼륨 섀도 복사본 서비스  (1) 2024.09.25
[Sysinternals] 프로세스 모니터  (0) 2024.08.15