<#
.SYNOPSIS
Exports AD Computer information including Operating System details.
.DESCRIPTION
This script retrieves the Operating System, Service Pack, and Version
from the "Operating System" tab of each AD computer object and exports
the results to a CSV file.
#>
# Import Active Directory module (required)
Import-Module ActiveDirectory
# Define output file path
$ExportPath = "C:\Temp\AD_Computers_OS_Report.csv"
# Retrieve computer objects with OS details
$computers = Get-ADComputer -Filter * -Property Name, OperatingSystem, OperatingSystemVersion, OperatingSystemServicePack, LastLogonDate
# Select relevant details
$results = $computers | Select-Object `
Name,
OperatingSystem,
OperatingSystemVersion,
OperatingSystemServicePack,
@{Name='LastLogonDate'; Expression={($_.LastLogonDate).ToString("yyyy-MM-dd HH:mm:ss")}}
# Export results to CSV
$results | Export-Csv -Path $ExportPath -NoTypeInformation -Encoding UTF8
Write-Host "✅ Report generated successfully: $ExportPath"