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.