无法通过计划任务从powershell脚本访问安全事件日志

无法通过计划任务从powershell脚本访问安全事件日志,powershell,Powershell,我正在尝试每一小时通过schedule task从Powershell脚本获取Windows安全事件日志,我正在以最高权限运行schedule task,但仍然得到“未经授权的操作”它在Powershell ISE和admin中正常工作,我在HKLM\System\CurrentControlSet\Services\eventlog\Security中添加了权限,并授予了读/写权限,但仍然存在相同的问题,请帮助我 下面是脚本。 脚本更新 #Security log $ScriptStart =

我正在尝试每一小时通过schedule task从Powershell脚本获取Windows安全事件日志,我正在以最高权限运行schedule task,但仍然得到“未经授权的操作”它在Powershell ISE和admin中正常工作,我在HKLM\System\CurrentControlSet\Services\eventlog\Security中添加了权限,并授予了读/写权限,但仍然存在相同的问题,请帮助我

下面是脚本。 脚本更新

#Security log
$ScriptStart = Get-Date
$PreviousTime = $ScriptStart.AddHours(-1)
$destination= '\\servername\Security_Logs\'
$output = (Get-WmiObject -Class Win32_ComputerSystem -Property Name).Name
$dest = "$destination$output$Date"
if (-not (Test-Path -LiteralPath $dest)) {
New-Item -Type Directory -Path $dest | Out-Null
$security = Get-WinEvent  @{ logname="security"; starttime=$PreviousTime;endtime=$ScriptStart } | select logname,timecreated,id,LevelDisplayName,message 
if ($security) {
 $security | Export-Csv $dest\Security.$Date.csv -NoTypeInformation -Append
} else {
'no files to copy' | Set-Content "$dest\nofile.txt"
}
}

如何在作业调度程序中启动它?也许将这些信息包括在内是有意义的

也许这里的答案是上浮的 可以帮助您正确启动它

powershell -noprofile -executionpolicy bypass -file C:\path\event4740.ps1

确保在创建任务时以管理员身份启动任务计划程序。运气不好,问题仍然相同。请从bat文件调用powershell脚本,批处理文件包含:powershell.exe-文件c:\log file path\script.ps1计划任务设置:程序/脚本:c:\logfile path\\bat.bat起始位置(可选):c:\logfile path\n我无法直接从计划任务运行powershell脚本,因此我在计划任务中创建了批处理文件和计划批处理文件。您可以尝试使用:powershell-noprofile-executionpolicy bypass-file c:\log file path\script.ps1script运行,但无法获取安全事件您将任务设置为以系统(不仅是管理员,而且是本地主机上的系统)当我使用系统运行任务时,它会运行很长时间,并且不会获得安全事件。