Get All Users' Profile Data In SharePoint Custom List Using PowerShell

Today, I got a requirement from my client. They want all users' profile data in a SharePoint custom list using PowerShell Command.

For Example - Display Name, Email id, Phone Number etc.

Using the below command, you can get all users' profile data in a SharePoint custom list.

Before this step, verify if your AD configuration service is activated or not. If it's not activated, please follow this link

https://sharepointumar.wordpress.com/2017/07/04/sync-user-profile-service-application-with-ad-map-sharepoint-properties-when-using-adi-active-directory-import/

After completing the AD sync Part.

SharePoint
  1. #Add SharePoint PowerShell SnapIn  
  2. if not already added  
  3. if ((Get - PSSnapin "Microsoft.SharePoint.PowerShell" - ErrorAction SilentlyContinue) - eq $null) {  
  4.     Add - PSSnapin "Microsoft.SharePoint.PowerShell"  
  5. }  
  6. $site = new - object Microsoft.SharePoint.SPSite("http://sp1:1010/");  
  7. $ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site);  
  8. #Get UserProfileManager from the My Site Host Site context  
  9. $ProfileManager = new - object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)  
  10. $AllProfiles = $ProfileManager.GetEnumerator()  
  11. # Open SharePoint List  
  12. $SPServer = "http://sp1:1010/"  
  13. $SPAppList = "Lists/PowerShellCMD/"  
  14. $spWeb = Get - SPWeb $SPServer  
  15. $spData = $spWeb.GetList($SPAppList)  
  16. foreach($profile in $AllProfiles) {  
  17.     #Create a new item  
  18.     $newItem = $spData.Items.Add()  
  19.     # Add properties to this list item  
  20.     $DisplayName = $profile.DisplayName  
  21.     $AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value  
  22.     $newItem["DispName"] = $DisplayName  
  23.     $newItem["AccName"] = $AccountName  
  24.     write - host "Profile for account ", $AccountName  
  25.     $newItem.Update()  
  26. }  
If this is helpful for you, please share and follow me for more real word examples. Stay tuned!

Below is our output:
 SharePoint