私は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 を実行するために Run-As Administrator を選択しました。
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.