【问题标题】:unable to access Security event log from powershell script through schedule task无法通过计划任务从 powershell 脚本访问安全事件日志
【发布时间】:2017-09-28 20:31:36
【问题描述】:

我正在尝试每隔一小时通过计划任务从 Powershell 脚本中获取 Windows 安全事件日志,我正在以最高权限运行计划任务,但我仍然收到“未经授权的操作”,它在 Powershell ISE 和管理员中运行良好,我在 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


【解决方案1】:

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

也许这里是赞成的答案 Powershell script does not run via Scheduled Tasks 可以帮助您正确启动它。

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

【讨论】:

  • 我从 bat 文件中调用 powershell 脚本,批处理文件包含:powershell.exe -file c:\log-file-path\script.ps1 调度任务设置:程序/脚本:c:\logfile- path\\bat.bat start in (optionl): c:\logfile-path\ 我无法直接从调度任务运行 powershell 脚本,所以我在调度任务中创建了一个批处理文件和调度批处理文件
  • 你可以试试:powershell -noprofile -executionpolicy bypass -file c:\log-file-path\script.ps1
  • 脚本正在运行但无法获取安全事件
  • 您是否将任务设置为以 SYSTEM 身份运行(不仅仅是管理员,而是本地主机上的 SYSTEM)
  • 当我使用 SYSTEM 运行任务时,它运行了很长时间并且没有收到安全事件。
猜你喜欢
  • 2020-11-06
  • 2014-05-05
  • 2013-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-02
  • 1970-01-01
  • 2017-05-05
相关资源
最近更新 更多