Powershell v2获取事件日志:试图执行未经授权的操作



我使用的是Powershell v2,这是我的脚本

param([string]$Sender_IP=$(throw " Sender's IP is required."))
$eventList = @()
Get-EventLog "Security" -computername $Sender_IP `
        | Where -FilterScript {$_.EventID -eq 4624 -and $_.ReplacementStrings[4].Length -gt 10 -and $_.ReplacementStrings[5] -notlike "*$"} `
        | Select-Object -First 2 `
        | foreach-Object {
            $row = "" | Select UserName, LoginTime
            $row.UserName = $_.ReplacementStrings[5]
            $row.LoginTime = $_.TimeGenerated
            $eventList += $row
            }
$UserId = $eventList[1].UserName
$UserID

代码唯一有效的时间是我传入当前服务器的IP地址。

我使用管理员凭据登录到此服务器,甚至选择了以管理员身份运行powershell。

为什么我在使用其他可以ping并具有管理访问权限的IP地址时会出现以下错误:

Get-EventLog : Attempted to perform an unauthorized operation.
At script_path_and_name.ps1:5 char:13
+ Get-EventLog <<<<  "Security" -computername $Sender_IP `
    + CategoryInfo          : NotSpecified: (:) [Get-EventLog], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetEventLogCommand

@Adi Inbar

远程注册表服务正在运行,防火墙已关闭。但它无法工作。

当我尝试使用服务帐户运行时,它也不起作用。

但奇怪的是,当我使用服务帐户运行,并输入我自己的IP地址时,我会出错,

Get-EventLog : Requested registry access is not allowed.

当您在机器上作为服务帐户运行它时,Powershell提示是否被提升?

我在机器上以非提升提示运行Powershell时遇到了这个错误(不允许访问注册表)。

你知道远程机器上的执行策略是什么吗?我不确定这是否重要,因为cmdlet会远程控制自己,但可能值得检查一下。

此外,仅供参考:

不管怎样,管道是一个自然的换行符,你不需要反勾号(只是不要在管道后面留下任何空格)。

例如:

cmdlet1 |
 cmdlet2 |
  cmdlet 3

最新更新