Import and Export users from user profiles service by Powershell

Source: Internet
Author: User

There are 2 services in SharePoint with the user Profile Service and the Users Profiles synchronization service, which Service is a prerequisite for user profile Serivce application to work.

User Profile Synchronization Service: used to synchronize AD account information to SharePoint Farm (actually to user profiles), we Service application creates a user profile-related database

User Profile Service: used to host the normal operation of the user Profile Service application.

The User Profile Service application only imports data (by configuring configure synchronization Connections) and does not provide an export data interface.

It is also not flexible to import data, such as we just want to import specific data, not the entire ad, for this particular requirement through PowerShell can be resolved.

As for how to start the User Profile Service and the user Profiles synchronization Servie, configure the User Profile Service Application This article does not elaborate

The learning goal of this article is: How to use PowerShell to import and export user information

    • Powershell Import users to user Profile service
$path= ' C:\userlist.csv '$site=$CAURL $context= Get-spservicecontext-Site $site $web= Get-spweb-Identity $siteTry{$UPM= New-object-typename Microsoft.Office.Server.UserProfiles.UserProfileManager-argumentlist $context}Catch{}    if($UPM-ne $NULL) {$userslist= Import-csv-Path $path $r=1;  for($count =0; $count-lt $userslist. Count; $count + +) {$user _name= $domain +"\ "+ $userslist [$count]. Userid-replace" ", ""                 if($UPM. UserExists ($user _name)) {}Else                   {                     Try{$profileproperty=$UPM. Createuserprofile ($user _name) $profileproperty [  "Manager"]. Value='  $profileproperty [Mail]. value= " $profileproperty ["Title"]. Value=" $profileproperty. Commit ()}Catch{Write-host-f Red ([String]::format ("{0} not Exist", $user _name)); }                 }             }    }
    • Powershell exports users from the user profile Service
$SITEURL ="CA URL"$outputFile="C:\sharepoint_user_profiles.csv"$serviceContext= Get-spservicecontext-Site $siteUrl $profilemanager= new-Object Microsoft.Office.Server.UserProfiles.UserProfileManager ($serviceContext); $profiles=$profileManager. GetEnumerator () $collection= @()foreach($profileinch$profiles) {$profileData=""|Select "AccountName","Preferredname","Manager","Office"," Location","Workemail","Assistant","Aboutme","Language","Pictureurl","Role"$profileData. AccountName= $profile ["AccountName"] $profileData. Preferredname= $profile ["Preferredname"] $profileData. Manager= $profile ["Manager"] $profileData. Office= $profile ["Office"] $profileData. location= $profile [" Location"] $profileData. Workemail= $profile ["Workemail"] $profileData. Assistant= $profile ["Assistant"] $profileData. Aboutme= $profile ["Aboutme"]. Value $profileData. Language= $profile ["Language"] $profileData. Pictureurl= $profile ["Pictureurl"] $profileData. Role= $profile ["Role"] # $collection+ = $profileData | Convertto-html-Fragment $collection+=$profileData} $collection| Export-csv $outputFile-notypeinformation-encoding"UTF8"

Import and Export users from user profiles service by Powershell

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.