I am trying to use a text file for a list of computers to query and get a list of all active and disabled local accounts on each of them.
This part is working fine for a single computer (named 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
}
By when I try to add a list of computers from a txt file, I get an empty output.
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
}}
Note that I am running Server 2008 which limits the PowerShell commands I can run.
Thanks in advance for any assistance provided