checking all on-premise DCs for last logon of csv list of users

somnio 1 Reputation point
2020-07-29T21:40:49.863+00:00

Hi all,

I hope all is well wherever you may be

I have been asked to check the last logon of around a thousand accounts, now listed in a csv. I can run

Import-csv "d:\temp\path_to.csv" |foreach-object {get-aduser $_.samaccountname -Properties lastlogondate} |select name,Lastlogon |Export-csv d:\temp\output\LastLogon.csv -NoTypeInformation

But know this only checks 1 DC. I need to check this against all DC's for completeness :)

so something like Get-ADDomainController -filter * would hopefully work but unfortunately PS doesn't like this and I can;t see where/how to complete the PS script.

As this seems the wrong command, could someone let me know what would be the correct one please

thank you :)

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,455 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 45,831 Reputation points
    2020-07-30T02:16:48.283+00:00

    I no longer have an AD to work with, but see if the script in the attachment works for you.

    14418-trythis.txt

    2 people found this answer helpful.