Import-Module ActiveDirectory $reportPath = ".\Reports\AD-User-Report.csv" if (!(Test-Path ".\Reports")) { New-Item -ItemType Directory -Path ".\Reports" | Out-Null } Get-ADUser -Filter * -Properties Enabled, LastLogonDate, Department, Title | Select-Object Name, SamAccountName, Enabled, Department, Title, LastLogonDate | Sort-Object Name | Export-Csv $reportPath -NoTypeInformation Write-Host "Active Directory user report created at $reportPath"