Import and Export users from user profile service By Powershell

Sharepoint中有2个服务User Profile ServiceUser Profile Synchronization Service跟用户息息相关,其中user profile service是user profile serivce application可运行的前提。

User Profile Synchronization Service:用于同步AD账号信息到Sharepoint Farm(实际是到User profile database),我们在配置user profile service application会创建user Profile相关的数据库

User Profile Service:用于承载user profile service application的正常运行。

user profile service application只有导入数据(通过配置Configure Synchronization Connections),并没有提供导出数据接口。

另外导入数据也不灵活,比如我们只想导入特定的数据,而不是整个AD, 对于这种特殊的需求通过powershell可以得到解决。

至于如何启动User profile service和user profile synchronization servie,配置user profile service application本文就不细说了

本文的学习目标是:如何用powershell来导入和导出用户信息

  • Powershell 导入用户到user profile service
    $path=‘c:\userlist.csv‘
    $site = $caUrl
    $context = Get-SPServiceContext -Site $site
    $web = Get-SPWeb -Identity $site
    try
    {
    $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 从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 ($profile in $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"
时间: 2024-08-01 10:46:36

Import and Export users from user profile service By Powershell的相关文章

汇编里的IMPORT和EXPORT

IMPORT ,定义表示这是一个外部变量的标号,不是在本程序定义的EXPORT ,表示本程序里面用到的变量提供给其他模块调用的.以上两个在汇编和C语言混合编程的时候用到刚看到一篇不错的BLOG,解说C和汇编混编的,虽然貌似是翻译ADS文档的,不过写的挺不错,通俗容易懂,可以看看其实汇编调用C貌似很简单B Main 就完了,直接跳过去,那传递参数怎么办?根据<嵌入式系统 Boot Loader 技术内幕>里面说的用弹簧床什么的来结局,不过暂时理解不了.用ADS的一个项目中同时放汇编的S文件和C语

win7提示“User Profile Service服务未能登录”

注:本文由Colin撰写,版权所有!转载请注明原文地址,谢谢合作! 最近,有个同事打电话告诉我说他的用户名无法登陆到系统,提示“User Profile Service服务未能登录,无法加载用户配置文件.” 针对此问题我首先做的是登入管理员用户检查User Profile Service服务,发现该服务启动正常,并且重启了一下该服务,再进行登入问题依旧.后面又尝试在msconfig中配置了启动项,也尝试了安全模式,问题依旧.最后只得上网搜索,最后通过恢复注册表解决该了问题. 问题分析: 第一种情

[转]Sqoop-1.4.4工具import和export使用详解

FROM :http://shiyanjun.cn/archives/624.html Sqoop可以在HDFS/Hive和关系型数据库之间进行数据的导入导出,其中主要使用了import和export这两个工具.这两个工具非常强大,提供了很多选项帮助我们完成数据的迁移和同步.比如,下面两个潜在的需求: 业务数据存放在关系数据库中,如果数据量达到一定规模后需要对其进行分析或同统计,单纯使用关系数据库可能会成为瓶颈,这时可以将数据从业务数据库数据导入(import)到Hadoop平台进行离线分析.

【Android】Android import和export使用说明 及 export报错:jarlist.cache: Resource is out of sync with the file syst解决

在Android开发export项目时发现有时会报错,内容如下: Problems were encountered during export:  Error exporting PalmIdentify/bin/jarlist.cache: Resource is out of sync with the file system: '/PalmIdentify/bin/jarlist.cache'.    Resource is out of sync with the file syste

Sqoop-1.4.4工具import和export使用详解

Sqoop-1.4.4工具import和export使用详解 Sqoop可以在HDFS/Hive和关系型数据库之间进行数据的导入导出,其中主要使用了import和export这两个工具.这两个工具非常强大,提供了很多选项帮助我们完成数据的迁移和同步.比如,下面两个潜在的需求: 业务数据存放在关系数据库中,如果数据量达到一定规模后需要对其进行分析或同统计,单纯使用关系数据库可能会成为瓶颈,这时可以将数据从业务数据库数据导入(import)到Hadoop平台进行离线分析. 对大规模的数据在Hadoo

ES6学习笔记&lt;五&gt; Module的操作——import、export、as

import export 这两个家伙对应的就是es6自己的 module功能. 我们之前写的Javascript一直都没有模块化的体系,无法将一个庞大的js工程拆分成一个个功能相对独立但相互依赖的小工程,再用一种简单的方法把这些小工程连接在一起. 这有可能导致两个问题: 一方面js代码变得很臃肿,难以维护 另一方面我们常常得很注意每个script标签在html中的位置,因为它们通常有依赖关系,顺序错了可能就会出bug 在es6之前为解决上面提到的问题,我们得利用第三方提供的一些方案,主要有两种

win7开机登录提示【user profile service未能登录】

系统环境 win7专业版(x64) 企业域用户 问题描述 企业采用单域环境,用户在登录系统时提示[user profile service未能登录,无法加载用户配置文件] 名词解释 [User Profile Service 服务 ] 此服务负责加载和卸载用户配置文件.如果已停止或禁用此服务,用户将无法再成功登录或注销,应用程序在获取用户数据时可能会出问题,而且为接收配置文件事件通知注册的组件将无法接收这些通知. 解决方法 开机按F8进入到安全模式,登录系统(如果只是标准账户有问题,管理员账户没

User Profile Service Application 配置同步连接时,报 MOSS MA not found

最近在试着配置"我的网站",不知什么原因在配置同步连接时报:MOSS MA not found 搜索发现,需要启动Forefront Identity Manager Service服务,右击选择启动即可,注意,如果你的已启动,就重新启动.   参看: http://mohamedelkassas.wordpress.com/2013/03/15/moss-ma-not-found-user-profile-syncronization-failure/ User Profile Se

PL/SQL Developer import and export database method and illustrate

PL/SQL Developer import and export database method and illustrate HOW WELL DO YOU KNOW THE APPLE UNIVERSE? In 2015, Apple became the first company worth how much? Which religion did Steve Jobs practice? What is one way Apple protects its secrecy? In