使用PowerShell和WMI读取安全日志
我正在构建一个脚本来从多台计算机读取安全日志。 使用 Get-EventLog 命令时,我可以毫无问题地从本地计算机读取安全日志,但问题是我无法在远程计算机上运行它(该脚本适用于 powershell v1)。 下面的命令永远不会返回任何结果,尽管与任何其他日志文件一起,它可以完美地工作:
gwmi 类 Win32_NTLogEvent | 其中 {$_.LogFile -eq "Security"}
我做了一些研究,我似乎是一个模拟问题,但是 Get-WmiObject 的 -Impersonation 选项似乎没有实现。 无论如何,这个问题有解决办法吗? 解决方案可以以某种方式在远程计算机上运行 Get-EventLog,或者处理模拟问题以便可以访问安全日志。 谢谢
I'm building a script to read the Security Log from several computers. I can read the Security log from my local machine with no problem when using the Get-EventLog command, but the problem with it is that I can't run it against a remote machine (the script is for powershell v1). The command below never returns any results, although that with any other LogFile, it works perfectly:
gwmi -Class Win32_NTLogEvent | where {$_.LogFile -eq "Security"}
I've done some research, and I seems to be a impersonation issue, but the -Impersonation option for the Get-WmiObject does not seem to be implemented. Is there anyway around this problem? The solution could be running the Get-EventLog on a remote machine somehow, or dealing with the impersonation issue so that the security log can be accessed.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以直接使用 .NET,而不是通过 WMI。 下面的脚本块将为您提供安全日志中的第一个条目
You could use .NET directly instead of going through WMI. The scriptblock below will give you the first entry in the security log
您是否尝试过使用 -Credential 参数? 另外,使用filter参数而不是where-object,它只获取安全事件(where-object从所有日志中获取所有事件,然后才执行过滤)
gwmi Win32_NTLogEvent -filter "LogFile='Security'" -computer comp1, comp2 - 凭据域\用户
Have you tried to use the -Credential parameter? Also, use the filter parameter instead of where-object, it gets just the security events (where-object gets ALL events from all logs and only then performs the filtering)
gwmi Win32_NTLogEvent -filter "LogFile='Security'" -computer comp1,comp2 -credential domain\user