Powershell Script to Query last machine domain authentication local and from VPN

Andrew N. Kowtalo
Andrew N. Kowtalo used Ask the Experts™
on
Hi Gents,

I am trying to do an AD cleanup of machines and need a working script I can run a query on to show last machine login or domain authentication for machines that VPN in from the field to the domain and export to a .csv file.  Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
show last machine login
Get-ADComputer -Filter { operatingSystem -like '*' } -Properties Name, description, OperatingSystem, OperatingSystemVersion, LastLogonTimeStamp, lastLogon, canonicalName |
Where-Object { Test-Connection -ComputerName $_.Name -Count 1 -Quiet } |
Select-Object -Property Name,
    ipv4address,
    description,
    OperatingSystem,
    OperatingSystemVersion,
    @{N="LastLogonTimeStamp";E={[datetime]::FromFileTime($_.LastLogonTimeStamp)}},
    @{N="LastLogon";E={[datetime]::FromFileTime($_.lastLogon)}},
    @{n = 'CN'; e={Split-Path $_.CanonicalName -Parent}} |
Sort-Object Name | Export-Csv -Path C:\TEMP\Result.csv -NoTypeInformation

Open in new window


The code above will do like the tile and only returns the result of online computer in the C:\TEMP\Result.csv file.
Andrew N. KowtaloSupport Center Engineer

Author

Commented:
Thank you for the response.  I will give this a try.
Andrew N. KowtaloSupport Center Engineer

Author

Commented:
There are some edits that need to be made which changes specifically do I specify the domain info?

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