Powershell Script to List Sharepoint 2013 User Profiles

Purpose

Script

Revisions

Purpose

Retrieve user profile information from Sharepoint. NOTE: Make sure the account you are running this account under has Full Access to the User Profile Service (see: https://bramdejager.wordpress.com/2013/02/14/when-setting-the-mysitehosturl-i-get-a-userprofileapplicationnotavailableexception/).

Script

    $site = new-object Microsoft.SharePoint.SPSite("http://sharepoint_site_url/");  

    $ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site);  

    #Get UserProfileManager from the My Site Host Site context

    $ProfileManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServiceContext)    

    $AllProfiles = $ProfileManager.GetEnumerator()  

    foreach($profile in $AllProfiles)  

    {  

        $DisplayName = $profile.DisplayName  

        $AccountName = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::AccountName].Value  

        $EmailAddr   = $profile[[Microsoft.Office.Server.UserProfiles.PropertyConstants]::WorkEmail].Value  

        #Here goes writing Logic to your SharePoint List + Check if account already existing in the SharePoint list then ignore writing.......

        write-host $DisplayName "," $AccountName "," $EmailAddr

    }  

    write-host "Finished."

    $site.Dispose()

Revisions

PS113017

Initial Version

THIS INFORMATION IS PROVIDED “AS IS” WITH NO WARRANTY OF ANY KIND AS TO THE ACCURACY OF ITS CONTENT.