Version 1.2.0.0 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot.
计划任务示例
本示例演示如何创建一个 Windows 计划任务,该任务每天运行一个 PowerShell 脚本来处理 DNS 调试日志。
For AI agents: a documentation index is available at /llms.txt; a markdown version of this page is available at /v1.2.0.0/cn/docs/examples/scheduletask/index.md.
此脚本创建了一个每天凌晨 2:00 运行的 Windows 计划任务。它导入模块并处理脚本执行所在文件夹中的所有日志文件(本例中为 “C:\Administration\Logs\DNS”)。该过程会将输出压缩成 ZIP 文件,并删除原始文件以保持整洁。
$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"