Import-Module ActiveDirectory -ErrorAction Stop

$out = 'C:\Apps\all_ad_users.csv'

Get-ADUser -Filter * -Properties mail,telephoneNumber,mobile,fax,physicalDeliveryOfficeName,department,title,Enabled |
  Select-Object @{
      Name='Name';Expression={$_.Name}
    }, @{
      Name='SamAccountName';Expression={$_.SamAccountName}
    }, @{
      Name='Mail';Expression={$_.mail}
    }, @{
      Name='Telephone';Expression={$_.telephoneNumber}
    }, @{
      Name='Mobile';Expression={$_.mobile}
    }, @{
      Name='Fax_business';Expression={$_.fax}
    }, @{
      Name='Office';Expression={$_.physicalDeliveryOfficeName}
    }, @{
      Name='Department';Expression={$_.department}
    }, @{
      Name='Title';Expression={$_.title}
    }, @{
      Name='Enabled';Expression={$_.Enabled}
    } |
  Tee-Object -Variable Results |
  Export-Csv -Path $out -NoTypeInformation -Encoding UTF8

# konzolra formázott megjelenítés (szükség szerint szűrj)
$Results | Format-Table Name,SamAccountName,Mail,Telephone,Mobile,Fax_business,Office,Department,Title,Enabled -AutoSize

Write-Host "Kimenet: $out ($($Results.Count) felhasználó)"
