Steps
  1. Open your PowerShell Window.
  2. Copy the code given below and paste it.
  3. Run the code given below.
  4. Open your SharePoint site.
  5. Check execution completed sucessfully.
  1. Code:
  2. # -----------------------------------------------------------------------------
  3. # Script :Export Active Directory Users Value in CSV
  4. # Author : Gowtham Rajamanickam
  5. # Date : February 16 2017
  6. # Version :1.0
  7. # -----------------------------------------------------------------------------
  8. $currentdate = Get-Date -Format ddmmyyyy:ss
  9. $csvreportfile = "C:\outputfiles\reportdate.csv"
  10. #import the ActiveDirectory Module
  11. Import-Module ActiveDirectory
  12. Get-ADUser -server $ADServer -searchbase "$SearchLoc" -Properties * -Filter * |
  13. Select-Object @{Label = "First Name";Expression = {$_.GivenName}},
  14. @{Label = "LastName";Expression = {$_.Surname}},
  15. @{Label = "DisplayName";Expression = {$_.DisplayName}},
  16. @{Label = "Logon Name";Expression = {$_.sAMAccountName}},
  17. @{Label = "Job Title";Expression = {$_.Title}},
  18. @{Label = "Company";Expression = {$_.Company}},
  19. @{Label = "Description";Expression = {$_.Description}},
  20. @{Label = "Department";Expression = {$_.Department}},
  21. @{Label = "City";Expression = {$_.City}},
  22. @{Label = "State";Expression = {$_.st}},
  23. @{Label = "Post Code";Expression = {$_.PostalCode}},
  24. @{Label = "Country/Region";Expression = {if (($_.Country -eq 'GB') ) {'United Kingdom'} Else {''}}},
  25. @{Label = "Email";Expression = {$_.Mail}},
  26. @{Label = "Last LogOn Date";Expression = {$_.lastlogondate}} |
  27. Export-Csv -Path $csvreportfile -NoTypeInformation
Thanks for reading my blog.