Reputation: 13
I'm using a text file generated from AD of disabled users names, e.g. jdoakes. I am using the following script to obtain the last time the user logged in. When ran, it is only returning non-disabled user. Any way to make this work?
Get-Content oldusers.txt |
Get-ADUser -Filter {Enabled -eq $true} -Properties Name,Manager,LastLogon |
Select-Object Name, Manager,
@{n='LastLogon';e={[DateTime]::FromFileTime($_.LastLogon)}}
It doesn't return any of the user names in the text file.
Upvotes: 1
Views: 1580
Reputation: 47792
You can't use -Filter
with -Identity
(identity is the parameter you're binding to when you pipe). You'll have to filter after the fact:
Get-Content oldusers.txt |
Get-ADUser -Properties Name,Manager,LastLogon |
Where-Object -FilterScript {
$_.Enabled
} |
Select-Object Name,Manager,@{n='LastLogon';e={[DateTime]::FromFileTime($_.LastLogon)}}
Upvotes: 2