Export all SharePoint Profiles to CSV – PowerShell

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

$CSV = "C:\UserProfiles.csv"

$contextSiteUrl = "https://mysites.contoso.com/"
$serviceContext = Get-SPServiceContext -Site $contextSiteUrl
$UPMGR = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);
$AllUserProfile= $UPMGR.GetEnumerator()

$Properties = @( 
            "SID", "ADGuid", "AccountName","FirstName","LastName","PreferredName","CountryCode","PersonalUrl","WorkPhone","Office","Department","Title","Manager","AboutMe","UserName","SPS-Skills","SPS-School","SPS-Dotted-line",
            "SPS-Peers","SPS-Responsibility","SPS-PastProjects","SPS-Interests","SPS-SipAddress","SPS-HireDate","SPS-Location","SPS-TimeZone","SPS-StatusNotes","Assistant","WorkEmail","SPS-ClaimID","SPS-ClaimProviderID","SPS-ClaimProviderType",
            "CellPhone","Fax","HomePhone","PictureURL"
           )

$Profilecollection = @()

foreach ($aProfile in $AllUserProfile) {
   $UserProfile = "" | select $Properties
   foreach ($field in $Properties) {
     if($aProfile[$field].Property.IsMultivalued) {
        try{
            $UserProfile.$field = $aProfile[$field] -join "|" } catch {}
     } else {
        try{
            $UserProfile.$field = $aProfile[$field].Value } catch {}
     }
   }
   if($aProfile.PersonalSite -ne $null)
     {
        try{
        $UserProfile.PersonalUrl = $aProfile.PersonalSite.Url  
        } catch {}
     }
   $Profilecollection += $UserProfile
}

$Profilecollection | Export-Csv $outputFile -NoTypeInformation
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s