【发布时间】:2020-09-03 18:20:20
【问题描述】:
我正在尝试使用文本文件作为计算机列表来查询并获取每个计算机上所有活动和禁用的本地帐户的列表。
这部分适用于单台计算机(名为 glm4453):
([ADSI]('WinNT://glm4453' -f $env:COMPUTERNAME)).Children | Where { $_.SchemaClassName -eq 'user' } | ForEach {
$user = ([ADSI]$_.Path)
$lastLogin = $user.Properties.LastLogin.Value
$enabled = ($user.Properties.UserFlags.Value -band 0x2) -ne 0x2
if ($lastLogin -eq $null) {$lastLogin = 'Never'}
Write-Host
Write-Host Username: ( " " * 5 ) $user.name
Write-Host Last Login: ( " " * 3 ) $lastLogin
Write-Host Enabled: ( " " * 6 ) $enabled
}
当我尝试从 txt 文件添加计算机列表时,我得到一个空输出。
foreach ($name in (get-content C:\temp\computer.txt))
{
([ADSI]('WinNT://$name' -f $env:COMPUTERNAME)).Children | Where { $_.SchemaClassName -eq 'user' } | ForEach {
$user = ([ADSI]$_.Path)
$lastLogin = $user.Properties.LastLogin.Value
$enabled = ($user.Properties.UserFlags.Value -band 0x2) -ne 0x2
if ($lastLogin -eq $null) {$lastLogin = 'Never'}
Write-Host
Write-Host Username: ( " " * 5 ) $user.name
Write-Host Last Login: ( " " * 3 ) $lastLogin
Write-Host Enabled: ( " " * 6 ) $enabled
}}
请注意,我运行的是 Server 2008,这限制了我可以运行的 PowerShell 命令。
提前感谢您提供的任何帮助
【问题讨论】:
标签: powershell adsi