C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Export Active Directory Users To CSV Using PowerShell
WhatsApp
Gowtham Rajamanickam
8y
12.7
k
0
4
25
Blog
Steps
Open your PowerShell Window.
Copy the code given below and paste it.
Run the code given below.
Open your SharePoint site.
Check execution completed sucessfully.
Code:
# -----------------------------------------------------------------------------
# Script :Export Active Directory Users Value in CSV
# Author : Gowtham Rajamanickam
# Date : February 16 2017
# Version :1.0
# -----------------------------------------------------------------------------
$currentdate = Get-Date -Format ddmmyyyy:ss
$csvreportfile =
"C:\outputfiles\reportdate.csv"
#import the ActiveDirectory Module
Import-Module ActiveDirectory
Get-ADUser -server $ADServer -searchbase
"$SearchLoc"
-Properties * -Filter * |
Select-Object @{Label =
"First Name"
;Expression = {$_.GivenName}},
@{Label =
"LastName"
;Expression = {$_.Surname}},
@{Label =
"DisplayName"
;Expression = {$_.DisplayName}},
@{Label =
"Logon Name"
;Expression = {$_.sAMAccountName}},
@{Label =
"Job Title"
;Expression = {$_.Title}},
@{Label =
"Company"
;Expression = {$_.Company}},
@{Label =
"Description"
;Expression = {$_.Description}},
@{Label =
"Department"
;Expression = {$_.Department}},
@{Label =
"City"
;Expression = {$_.City}},
@{Label =
"State"
;Expression = {$_.st}},
@{Label =
"Post Code"
;Expression = {$_.PostalCode}},
@{Label =
"Country/Region"
;Expression = {
if
(($_.Country -eq
'GB'
) ) {
'United Kingdom'
} Else {
''
}}},
@{Label =
"Email"
;Expression = {$_.Mail}},
@{Label =
"Last LogOn Date"
;Expression = {$_.lastlogondate}} |
Export-Csv -Path $csvreportfile -NoTypeInformation
Thanks for reading my blog.
People also reading
Membership not found