【问题标题】:Powershell v2 Get-Eventlog: Attempted to perform an unauthorized operationPowershell v2 Get-Eventlog:试图执行未经授权的操作
【发布时间】:2013-08-05 18:39:02
【问题描述】:

我正在使用 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

@阿迪因巴

远程注册表服务正在运行,并且防火墙已关闭。然而它不起作用。

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

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

Get-EventLog : Requested registry access is not allowed.

【问题讨论】:

  • 确保远程注册表服务正在目标计算机上运行。另外,请尝试暂时关闭其中一个防火墙,看看是否有障碍。
  • 远程注册表服务正在运行,并且防火墙已关闭。然而它不起作用。当我尝试使用服务帐户运行时,它也不起作用。但奇怪的是,当我使用服务帐户运行并输入我自己的 IP 地址时出现错误,Get-EventLog : Requested registry access is not allowed.

标签: powershell powershell-2.0 elevated-privileges


【解决方案1】:

当你在你的机器上作为服务账户运行它时,Powershell 提示是否提升了?

在我的机器上以非提升提示符运行 Powershell 时出现该错误(不允许访问注册表)。

您知道远程机器上的执行策略是什么吗?我不确定 cmdlet 远程本身是否重要,但可能值得检查。

另外,仅供参考:

无论如何,管道是一个自然的换行符,你不需要反引号(只是不要在管道之后留下任何空格)。

例如:

cmdlet1 |
 cmdlet2 |
  cmdlet 3

【讨论】:

    猜你喜欢
    • 2018-05-09
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-01
    • 1970-01-01
    相关资源
    最近更新 更多