【发布时间】: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