40 lines
1.4 KiB
PowerShell
40 lines
1.4 KiB
PowerShell
Import-Module ActiveDirectory -ErrorAction Stop
|
|
|
|
$in = 'C:\Tools\users.txt'
|
|
$out = 'C:\Tools\selected_users.csv'
|
|
|
|
# Felhasználónevek beolvasása a txt-ből, üres sorokat kihagyva, szóközöket levágva
|
|
$userList = Get-Content -Path $in | Where-Object { $_.Trim() -ne "" } | ForEach-Object { $_.Trim() }
|
|
|
|
# AD-lekérdezés és szűrés a txt alapján
|
|
Get-ADUser -Filter * -Properties mail,telephoneNumber,mobile,fax,physicalDeliveryOfficeName,department,title,Enabled |
|
|
Where-Object { $userList -contains $_.Name } |
|
|
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
|
|
$Results | Format-Table Name,SamAccountName,Mail,Telephone,Mobile,Fax_business,Office,Department,Title,Enabled -AutoSize
|
|
|
|
Write-Host "Kimenet: $out ($($Results.Count) felhasználó)"
|