【客户需求】
客户环境是SharePoint 2016
客户希望批量把本地用户头像图片上传到SharePoint网站对应的用户头像上
【解决办法】
方法一:
发头像批量上传到AD中,再通过SharePoint2016 的MIM同期头像信息。
方法二:
使用PowerShell手动上传头像
1.将头像图片放到SharePoint服务器上
2.在该服务器的IIS里创建web site用于http访问头像
3.创建CSV文件,写入头像图片与ad用户关系
4.执行以下powershell
[void][system.reflection.assembly]::loadwithpartialname("Microsoft.Office.Server.UserProfiles");
$csvFile = "C:\1\photo.csv";
$MySiteUrl = "http://sp2016-3/my";
$site = Get-SPSite $MySiteUrl;
$context = Get-SPServiceContext $site;
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context);
$csv = import-csv -path $csvFile;
foreach ($line in $csv)
{
$user_name = "contoso\" + $line.domain_user_name;
$up = $profileManager.GetUserProfile($user_name);
if($up)
{
$up["PictureURL"].Value = $line.emp_id;
$up.Commit();
write-host $user_name,"--->",$up.DisplayName,"--->",$line.emp_id;
$up = $null;
}
}
5.执行下面的PowerShell,用于将上传的头像创建3个不同尺寸头像,优化显现。
Update-SPProfilePhotoStore -MySiteHostLocation http://sp2016-3/my
6.执行后查看效果