Powershell Script to Retrieve AD Computers Properties

# Retrieve Active Directory computer properties such as LastLogonDate.

# The list of machine need to be added in hosts.txt file in script folder

# The result will be saved to Output.csv file in script folder.

Import-Module ActiveDirectory
$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path
$input = $directorypath + "\host.txt"
$output = $directorypath + "\output.csv"
Get-Content $input | ForEach-Object {
Get-ADComputer $_ -Properties * | Select-Object Name,LastLogonDate,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion,WhenCreated,Description
}   | Export-Csv $output

Related Posts:

Explore More Intune Guides

Continue building your Microsoft Intune skills with step-by-step tutorials covering device management, application deployment, automation, and troubleshooting.

  • Microsoft Intune Learning – Explore comprehensive guides on device enrollment, compliance policies, application deployment, Windows updates, and more.
  • Intune Automation – Discover PowerShell and Microsoft Graph automation solutions to simplify repetitive Intune administration tasks.

Subscribe to Techuisitive Newsletter

Be the first to know about our new blog posts. Get our newsletters directly in your inbox and stay up to date about Modern Desktop Management technologies & news.

Scroll to Top