我正在使用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地址时,代码才能正常工作。
我使用管理员凭据登录到此服务器,甚至选择了Run-As administrator来运行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.发布于 2013-08-19 22:38:32
当您在您的机器上以服务帐户运行它时,Powershell提示符是否提升了?
在我的机器上以非提升的提示运行Powershell时,我得到了那个错误(不允许访问注册表)。
您知道远程机器上的执行策略是什么吗?我不确定这是否重要,因为cmdlet本身是远程的,但它可能值得检查。
另外,仅供参考:
管道是一个自然的换行,无论如何,你不需要反标记(只是不要在管道后留下任何空格)。
例如:
cmdlet1 |
cmdlet2 |
cmdlet 3https://stackoverflow.com/questions/18065318
复制相似问题