728x90
Export AD Users to CSV using Powershell Script
Description:
We can easily export Active Directory users to CSV file using Powershell cmdlets Get-ADUser and Export-CSV. In this article, I am going to write Powershell script samples to Export AD Users to CSV file and Export AD Users from Specific OU to CSV file using Powershell Script.Summary:
Export AD Users to CSV using Powershell
The following command export the selected properties of all Active Directory users to CSV file. You can add more attributes as per your wish, refer this article:Get-ADUser Default and Extended Properties to know more supported AD attributes.1 2 3 4 | Import -Module ActiveDirectory Get -ADUser -Filter * -Properties * | Select -Property Name,Mail,Department | Export-CSV "C:\\AllADUsers.csv" -NoTypeInformation -Encoding UTF8 |
Export AD Users to CSV with Filter using Powershell
This command export the selected properties to CSV file of AD users whose City contains the text 'Austin'.Note: Refer this article:Get-ADUser Default and Extended Properties to know more supported AD attributes.
1 2 3 4 | Import -Module ActiveDirectory Get -ADUser -Filter 'City -like "*Austin*"' -Properties * | Select -Property Name,City,Mail,Department,DistinguishedName | Export-CSV "C:\\ADUsers.csv" -NoTypeInformation -Encoding UTF8 |
Export AD Users by LDAP Filter:
Instead of SQL Like Filter, you can also use LDAP Filter to select only required users. Refer this article (AD LDAP Filter Examples) to get more LDAP filter examples. The below command exports all the users who are belongs to Admin department.1 2 3 4 | Import -Module ActiveDirectory Get -ADUser -LDAPFilter '(Department=*Admin*)' -Properties * | Select -Property Name,City,Mail,Department,DistinguishedName | Export-CSV "C:\\AdminUsers.csv" -NoTypeInformation -Encoding UTF8 |
Export ADUsers CSV output:
Export AD Users from specific OU to CSV using Powershell
We can set target OU scope by using the parameter SearchBase. This following command select all the AD users from the Organization Unit 'Austin' and export it to CSV file.1 2 3 4 | Import -Module ActiveDirectory Get -ADUser -Filter * -SearchBase "OU=Austin,DC=TestDomain,DC=Local" -Properties * | Select -Property Name,Mail,Department | Export-CSV "C:\\AustinUsers.csv" -NoTypeInformation -Encoding UTF8 |
Thanks,
Morgan
Software Developer
====================================================================================
Import-CSV -Path .\csv_file.csv | ForEach-Object {
Get-ADUser -Filter "ProxyAddresses -like '*$($_.name)*'" -Properties ProxyAddresses,EmailAddress | select EmailAddress,SamAccountName
} | Export-CSV .\results.csv -NoTypeInformation
====================================================================================
Import-CSV -Path .\csv_file.csv | ForEach-Object {
Get-Recipient $_ |
Select PrimarySMTPAddress,SamAccountName
} | Export-CSV .\results.csv -NoTypeInformation
============================================================================================
get-aduser -Properties * -Filter * | ? {$_.telephonenumber -ne $null} | select displayname,samacco
untname,telephonenumber,mobile | export-csv -Path d:\alluser.csv -NoTypeInformation -Encoding UTF8
foreach ($user in (get-content d:\telephone.txt)){Get-ADUser -Filter {telephoneNumber -like $user}
-Properties * |select displayname, Samaccountname,telephonenumber >> d:\telephone_user.txt}
728x90
'IT이야기 > ActiveDirectory' 카테고리의 다른 글
sid,SidHistory 값 출력하기 (0) | 2021.08.04 |
---|---|
그룹 멤버 포함 체크 여부 (0) | 2021.08.04 |
Windows 2003 DC에서 Windows 2008 DC로 FSMO(작업마스터) 넘기기 (0) | 2016.07.12 |
(그룹 정책) 소프트웨어 제한 정책을 사용한 특정 프로그램 사용 차단 (0) | 2016.07.12 |
(그룹 정책) IPSec을 사용한 인터넷 (Port 80) 차단 (0) | 2016.07.12 |