Last Logon Date of Machines

Terellion
Terellion used Ask the Experts™
on
Hi there, I have a list of machines in a CSV and i'd like to import the CSV into powershell and then add a column with a list of last logon dates from Active Directory for these machines and output to a new file. Is this possible?

Thanks so much!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Here is a step by step tutorial for what you are asking for with visual aids and code :)
 
Get Active Directory user account last logged on time (PowerShell)
http://gallery.technet.microsoft.com/scriptcenter/Get-Active-Directory-user-246f17c7

Author

Commented:
Hi there, thats for user accounts :( Please assist with this, i tried importing them using that link but it said they all didn't exist even though they do. Thanks
Top Expert 2014
Commented:
Assuming your .CSV looks like this.
Name
comp1
comp2

Open in new window

Tip for the future - if you only have one column, leave out the header and just have a simple text file rather than a .CSV.

This should work.
Import-Module ActiveDirectory
Import-CSV input.csv | ForEach `
{
    Get-ADComputer $_.name -Properties LastLogonDate
} | Select Name,LastLogonDate |
 Export-CSV output.csv -notype

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial