powershell - 是否有显示实际机器的 AD 锁定脚本
问题描述
有谁知道或有一个脚本可以告诉您锁定 AD 帐户的实际设备。我有一个工作脚本,列出了过去 3 天内锁定的所有用户,告诉我 DC 已锁定。而不是必须连接到这个或通过事件日志并找到事件ID,我想知道是否有一个PS脚本可以输出到哪里。然后我们可以去所述设备并修复。
谷歌提出了一些建议,但不是最明确的,有些只是做了我通过当前脚本已经可以得到的东西。
谢谢
解决方案
这将返回一个 PsObjects 数组,其中:
- 属性
TargetUserName
保存被锁定的用户 SamAccountName - 属性
TargetDomainName
包含锁定源自的计算机名称 - 属性
EventDate
将显示锁定发生的时间和日期
代码:
# get the domain controller that has the PDC Emulator Role
$pdc = (Get-ADDomain).PDCEmulator
$splat = @{
FilterHashtable = @{LogName="Security";Id=4740}
MaxEvents = 100
ComputerName = $pdc
Credential = Get-Credential -Message "Please enter credentials for '$pdc'"
}
$lockedOut = Get-WinEvent @splat | ForEach-Object {
# convert the event to XML and grab the Event node
$eventXml = ([xml]$_.ToXml()).Event
# create an ordered hashtable object to collect all data
# add some information from the xml 'System' node first
$evt = [ordered]@{
EventDate = [DateTime]$eventXml.System.TimeCreated.SystemTime
Level = [System.Diagnostics.Tracing.EventLevel]$eventXml.System.Level
}
# next see if there are childnodes under 'EventData'
if ($eventXml.EventData.HasChildNodes) {
$eventXml.EventData.ChildNodes | ForEach-Object {
$name = if ($_.HasAttribute("Name")) { $_.Name } else { $_.LocalName }
$value = $_.'#text'
if ($evt[$name]) {
# if an item with that name already exists, make it an array and append
$evt[$name] = @($evt[$name]) + $value
}
else { $evt[$name] = $value }
}
}
# output as PsCustomObject. This ensures the $result array can be written to CSV easily
[PsCustomObject]$evt
}
# output on screen
$lockedOut | fl *
# output to csv file
$lockedOut | Export-Csv -Path 'D:\lockedout.csv' -NoTypeInformation
例如,如果您想搜索特定用户 (SamAccountName),只需执行
$lockedOut | Where-Object { $_.TargetUserName -eq 'UserSamAccountName' }
希望有帮助
推荐阅读
- box - n维中两个轴对齐框之间的最小距离
- vba - VBA 在连接函数中保留超链接
- angular - 无法在传单 setContent 函数中绑定组件
- ios - How to hide header and footer in WKWebView using Js and ios-14
- java - 在android java中调用一个类的方法到另一个类?
- python - “作业”对象在安排事件时没有属性“星期三”错误
- python - sqlite3.OperationalError:不明确的列名:视图
- android - 在显着披露中缺少信息
- plsql - PL SQL Apex_JSON - 解析元素名称
- python-3.x - 谁能建议如何快速抓取这个 https://www3.wipo.int/branddb/en/# 网站?