我一直在尝试获取应用程序、安全性和系统的事件查看器日志,并将输出存储到xml文件中。虽然应用程序和系统运行良好,但我遇到了安全性问题。我使用的凭据是从xml文件中读取的。这是我的代码的样子:
$main = (Get-Item .).FullName
Import-Module C:\repos\IPA\Tests\separate\GetCredsFromFile.psm1
Import-Module C:\repos\IPA\Tests\separate\SaveCredsToFile.psm1
function Get-EV {
param(
[Parameter(Mandatory)] [string] $logName,
[Parameter(Mandatory)] [string] $ServerIP,
[Parameter()] [datetime] $DateLimit = (Get-Date).AddDays(-7)
)
try {
if (-not(Test-Path "$main\creds.xml")) {
SaveCredsToFile -File "$main\creds.xml"
}
$creds = GetCredsFromFile -File "$main\creds.xml"
$datelimit = $DateLimit.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ")
$logs = Get-WinEvent -LogName $logname -ComputerName $ServerIP -Credential $creds -MaxEvents 10
$logs | Export-Clixml -Path "$copyto\$ServerIP - $logName.xml"
} catch {Write-Error $_.exception.message}
}
function Get-SELogs {
param(
[Parameter(Mandatory)] [string] $ServerIP,
[Parameter()] [string] $LogName,
[Parameter()] [string] $copyto = "$main\logdir\",
[Parameter()] [datetime] $OldDate
)
try{
switch ($LogName) {
"app" {
Get-EV -logName "Application" -ServerIP $ServerIP
}
"sys" {
Get-EV -logName "System" -ServerIP $ServerIP
}
"sec" {
Get-EV -logName "Security" -ServerIP $ServerIP
}
Default {
# Default gets all
$logNames = @("Application", "System", "Security")
foreach ($logName in $logNames){
Get-EV -logName $logName -ServerIP $ServerIP
}
}
}
} catch {
Write-Error $_.exception.message
}
}
Get-SELogs -ServerIP 192.168.1.176 -LogName sec
当我运行这段代码时,我得到了以下错误:
Get-WinEvent : Could not retrieve information about the Security log. Error: Attempted to perform an unauthorized operation..
At C:\repos\IPA\Tests\separate\Get-SELogs.ps1:20 char:17
+ ... $logs = Get-WinEvent -LogName $logname -ComputerName $ServerIP -C ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-WinEvent], Exception
+ FullyQualifiedErrorId : LogInfoUnavailable,Microsoft.PowerShell.Commands.GetWinEventCommand
Get-WinEvent : There is not an event log on the 192.168.1.176 computer that matches "Security".
At C:\repos\IPA\Tests\separate\Get-SELogs.ps1:20 char:17
+ ... $logs = Get-WinEvent -LogName $logname -ComputerName $ServerIP -C ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Security:String) [Get-WinEvent], Exception
+ FullyQualifiedErrorId : NoMatchingLogsFound,Microsoft.PowerShell.Commands.GetWinEventCommand
我验证的用户是否必须属于特定组或管理员?当前该用户属于“事件日志读取者”组。我一直在Internet上搜索,但无法找到答案。
1条答案
按热度按时间5lwkijsr1#
安全事件日志仅对计算机管理员开放。
由于您已将帐户添加到“Event Log Readers”组,因此需要将“BUILTIN\Event Log Readers”组添加到以下注册表项权限:
HKLM\系统\当前控制集\服务\事件日志\安全
仅此密钥
查询值、枚举子项、通知、读取控件
在域中,您可以使用组策略覆盖所有计算机:
组策略对象编辑器:计算机配置〉策略〉Windows设置〉安全设置