cmdlet用于获取哪台计算机锁定AD账户的信息。

问题描述 投票:0回答:1

我需要找出是哪台计算机在调用锁定我的账户。我可以在GUI中通过打开事件查看器并在安全日志中找到一个日志事件,但这很耗时,而且在我们的环境中,这种情况确实经常发生,我需要一个更快的解决方案。我写了这个命令。

Get-EventLog security -ComputerName DC -InstanceId 4740 | ? {$_.Message -like "MyUserName"} | FL

我也试过 -match 而不是 -like 但都没有得到任何结果。有谁知道用哪个接线员可以得到我需要的东西?

powershell events event-log windows-server user-accounts
1个回答
0
投票

像@vonPryz一样,我通常会使用altools,但它响应的DC的帐户被锁定,然后我遇到了下面的代码在。https:/thesysadminchannel.comget-account-lock-out-source-powershell。 看起来只是票,前提条件之一是允许远程事件视图访问要查询的DC。

网站的代码复制到下面,如果脱机了,所有功劳都是SysAdmin频道的Paul。

#requires -Module ActiveDirectory
#Import-Module ActiveDirectory -EA Stop

Function Get-AccountLockoutStatus {
<#
.Synopsis
This will iterate through all your domain controllers by default and checks for event 4740 in event viewer. To use this, you must dot source the file and call the function.
For updated help and examples refer to -Online version.


.DESCRIPTION
This will go through all domain controllers by default and check to see if there are event ID for lockouts and display the information in table with Username, Time, Computername and CallerComputer.
For updated help and examples refer to -Online version.


.NOTES  
Name: Get-AccountLockoutStatus
Author: The Sysadmin Channel
Version: 1.01
DateCreated: 2017-Apr-09
DateUpdated: 2017-Apr-09

.LINK
https://thesysadminchannel.com/get-account-lock-out-source-powershell -


.PARAMETER ComputerName
By default all domain controllers are checked. If a computername is specified, it will check only that.

.PARAMETER Username
If a username is specified, it will only output events for that username.

.PARAMETER DaysFromToday
This will set the number of days to check in the event logs.  Default is 3 days.

.EXAMPLE
Get-AccountLockoutStatus

Description:
Will generate a list of lockout events on all domain controllers.

.EXAMPLE
Get-AccountLockoutStatus -ComputerName DC01, DC02

Description:
Will generate a list of lockout events on DC01 and DC02.

.EXAMPLE
Get-AccountLockoutStatus -Username Username

Description:
Will generate a list of lockout events on all domain controllers and filter that specific user.

.EXAMPLE
Get-AccountLockoutStatus -DaysFromToday 2

Description:
Will generate a list of lockout events on all domain controllers going back only 2 days.

#>

[CmdletBinding()]
param(
    [Parameter(
        ValueFromPipeline=$true,
        ValueFromPipelineByPropertyName=$true,
        Position=0)]

    [string[]]     $ComputerName = (Get-ADDomainController -Filter * |  select -ExpandProperty Name),

    [Parameter()]
    [string]       $Username,

    [Parameter()]
    [int]          $DaysFromToday = 3

)


BEGIN {
    $Object = @()
}

PROCESS {
    Foreach ($Computer in $ComputerName) {
        try {
            $EventID = Get-WinEvent -ComputerName $Computer -FilterHashtable @{Logname = 'Security'; ID = 4740; StartTime = (Get-Date).AddDays(-$DaysFromToday)} -EA 0
            Foreach ($Event in $EventID) {
                $Properties = @{Computername   = $Computer
                                Time           = $Event.TimeCreated
                                Username       = $Event.Properties.value[0]
                                CallerComputer = $Event.Properties.value[1]
                                }
                $Object += New-Object -TypeName PSObject -Property $Properties | Select ComputerName, Username, Time, CallerComputer
            }

        } catch {
            $ErrorMessage = $Computer + " Error: " + $_.Exception.Message

        } finally {
            if ($Username) {
                    Write-Output $Object | Where-Object {$_.Username -eq $Username}
                } else {
                    Write-Output $Object
            }
            $Object = $null
        }

    }

}     


END {}

}
© www.soinside.com 2019 - 2024. All rights reserved.