powershell - 如何获取 AD 机器列表并有效获取上次登录的人的用户名
问题描述
我的任务是获取名称中包含 T44、T45、T46、T48 的机器列表/最后一个登录他们的用户名,然后将它们导出到 .CSV。
我已经做了很长的路...
获取机器列表 - 如“ T44 ”,然后通过Get-WMI
...查询它们
这就是我所拥有的:
Clear-Host
$T440 = Get-Content -Path C:\Users\khalifam\Desktop\Winver\T440.txt
$Results = foreach ($computer in $T440) {
# test if the compurer is on-line
if (!(Test-Connection -ComputerName $computer -Count 1 -Quiet)) {
Write-Warning "Computer '$computer' is off-line."
# skip this computer and carry on with the next iteration
continue
}
Get-WmiObject –ComputerName $computer –Class Win32_ComputerSystem | Select Username, PSComputerName
}
$Results |
Export-Csv -Path C:\Users\khalifam\Desktop\T440Names.csv
解决方案
推荐阅读
- javascript - How to add days into my date using angular pipe?
- java - 如何在 JUnit 测试中禁用/模拟 Spring EntityListener
- java - Java getting every second element from array list and using it as value for hash map
- python - How to cope around memory overflow with Pivot table?
- python - 我应该在哪里存储 Python3 模块?
- docker - docker-compose 多拱
- jquery - 循环遍历具有多个结果的变量
- google-apps-script - 获取应用程序脚本服务不可用:Gmail 帐户上的电子表格
- java - 在 UsernamePasswordAuthenticationFilter 或 Controller 中创建 JWT 令牌?
- javascript - 如何通过 ajax jquery/javascript 向服务器发送 OPTIONS 方法调用?