Version 1.2.1.0 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot.

Esempio di Attività Pianificata

Questo esempio mostra come creare un’attività pianificata di Windows che esegue uno script PowerShell per elaborare quotidianamente i log di debug DNS.

For AI agents: a documentation index is available at /llms.txt; a markdown version of this page is available at /v1.2.1.0/it/docs/examples/scheduletask/index.md.

Questo script crea un’attività pianificata di Windows che viene eseguita ogni giorno alle 2:00 AM. Importa il modulo ed elabora tutti i file di log nella cartella in cui viene eseguito lo script (in questo esempio “C:\Administration\Logs\DNS”). Il processo comprime l’output in file ZIP e rimuove l’originale per mantenere l’ordine.

$actionParams = @{
    Execute = "powershell.exe"
    Argument = '-ExecutionPolicy RemoteSigned -Command "Import-Module DNSServer.DebugLogParser; Get-ChildItem .\*.log | Sort-Object lastwritetime, Name -Descending | Convert-DNSDebugLogFile -ComputerName $env:COMPUTERNAME -Delimiter \";\" -OutputType Both -ContextFilter Packet -OutputCulture sv-SE -CompressOutput"'
    WorkingDirectory = "C:\Administration\Logs\DNS"
}
$Action = New-ScheduledTaskAction @actionParams

$Trigger = New-ScheduledTaskTrigger -Daily -At "2:00AM"

Register-ScheduledTask -TaskName "Process DNS Logs" -Action $Action -Trigger $Trigger -Description "Convert DNS debug logs to CSV daily"