Export Active Directory Users To CSV Using PowerShell

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.   
  9.        
  10.     $currentdate = Get-Date -Format ddmmyyyy:ss   
  11.    
  12.     $csvreportfile =  "C:\outputfiles\reportdate.csv"   
  13.       
  14.     #import the ActiveDirectory Module   
  15.     Import-Module ActiveDirectory   
  16.       
  17.       
  18.                   Get-ADUser -server $ADServer -searchbase "$SearchLoc" -Properties * -Filter * |    
  19.                   Select-Object @{Label = "First Name";Expression = {$_.GivenName}},    
  20.                   @{Label = "LastName";Expression = {$_.Surname}},   
  21.                   @{Label = "DisplayName";Expression = {$_.DisplayName}},   
  22.                   @{Label = "Logon Name";Expression = {$_.sAMAccountName}},   
  23.                   @{Label = "Job Title";Expression = {$_.Title}},   
  24.                   @{Label = "Company";Expression = {$_.Company}},   
  25.                   @{Label = "Description";Expression = {$_.Description}},   
  26.                   @{Label = "Department";Expression = {$_.Department}},    
  27.                   @{Label = "City";Expression = {$_.City}},   
  28.                   @{Label = "State";Expression = {$_.st}},   
  29.                   @{Label = "Post Code";Expression = {$_.PostalCode}},   
  30.                   @{Label = "Country/Region";Expression = {if (($_.Country -eq 'GB')  ) {'United Kingdom'} Else {''}}},   
  31.                                      
  32.                   @{Label = "Email";Expression = {$_.Mail}},   
  33.                   @{Label = "Last LogOn Date";Expression = {$_.lastlogondate}} |    
  34.                      
  35.                  
  36.                   Export-Csv -Path $csvreportfile -NoTypeInformation     
Thanks for reading my blog.