首页 > 解决方案 > 如何获取 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

标签: powershell

解决方案


推荐阅读