powershell 将图片设置为SharePoint 2010用户配置文件(UPS),图片来自本地路径。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 将图片设置为SharePoint 2010用户配置文件(UPS),图片来自本地路径。相关的知识,希望对你有一定的参考价值。

# ----------------------------------------------
# Author: Romain Blanchard
# Date: 22.03.2013
# Description: Set pictures to SharePoint 2010 User Profile (UPS), pictures comes from local path.
# ----------------------------------------------

# -- Initialize -- #
$LocalPath = "D:\Logica\Deploy\Leadership\SetPictures\Pictures"
$MySiteUrl = "http://rbla-sp2010-002/my/"
$mySiteHostSite = Get-SPSite $MySiteUrl
$mySiteHostWeb = $mySiteHostSite.OpenWeb()
$context = Get-SPServiceContext $mySiteHostSite
$profileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
$count = 0
$sleeptime = 0

# -- Script -- #
try
{   
	$localPhotosFolder = Get-ChildItem $LocalPath
	$spPhotosFolder = $mySiteHostWeb.GetFolder("User Photos")
	write-host "" -foregroundcolor Green
	
	$localPhotosFolder | ForEach-Object {
	   
		$spFullPath = $spPhotosFolder.Url + "/" + $_.Name		
		$domainName = $_.Name.Split(".")[0]
		$userName = $_.Name.Split(".")[1].Replace($_.Extension, "")
		$adAccount = $domainName + "\" + $userName
		
		$spFile = $spPhotosFolder.Files.Add($spFullPath, $_.OpenRead(), $true)
		$spImagePath = $mySiteHostWeb.Url + "/" + $spFile.Url
		if ($profileManager.UserExists($adAccount))
		{
			write-host "Uploading" $_.Name "picture..." -foregroundcolor Green -nonewline
			$up = $profileManager.GetUserProfile($adAccount)
			$up["PictureURL"].Value = $spImagePath
			$sleeptime = $sleeptime + 10
			$up.Commit()
			write-host "Done!" -foregroundcolor Green
		}
		else
		{
			write-host $adAccount "profile cannot be found!" -foregroundcolor Red
		}
	}		
	
	write-host ""
	write-host "----------------------------"
	write-host "Resizing pictures (this operation can take several minutes)..." -nonewline
	Start-Sleep -s 5
	Update-SPProfilePhotoStore –MySiteHostLocation $MySiteUrl | Out-Null
	Start-Sleep -s $sleeptime
	write-host "Done!" -foregroundcolor Green
	write-host "----------------------------"
	write-host ""
	
	$localPhotosFolder | ForEach-Object {
	
		$spFullPath = $spPhotosFolder.Url + "/" + $_.Name			
			
		$domainName = $_.Name.Split(".")[0]
		$userName = $_.Name.Split(".")[1].Replace($_.Extension, "")
		$adAccount = $domainName + "\" + $userName
		
		$spFile = "User Photos/$_.Name"
		$spResizedImagePath = $mySiteHostWeb.Url + "/User Photos/Profile Pictures/" + $domainName + "_" + $userName + "_LThumb.jpg"

		if ($profileManager.UserExists($adAccount))
		{
			$up = $profileManager.GetUserProfile($adAccount)
			$up["PictureURL"].Value = $spResizedImagePath
			$filecount = $mySiteHostWeb.GetFile($spResizedImagePath).Url
			if ($filecount -ne $null) {$count++}
			$up.Commit()								
		}
		else
		{
		
		}
	}
	
	write-host ""
	write-host "----------------------------"
	write-host "Resizing pictures (this operation can take several minutes)..." -nonewline
	Start-Sleep -s 5
	Update-SPProfilePhotoStore –MySiteHostLocation $MySiteUrl | Out-Null
	Start-Sleep -s $sleeptime
	write-host "Done!" -foregroundcolor Green
	write-host "----------------------------"
	write-host ""	
			
	$localPhotosFolder | ForEach-Object {
	
			$spFullPath = $spPhotosFolder.Url + "/" + $_.Name
			$spPhotosFolder.Files.Delete($spFullPath)
	}

	write-host $count" pictures has been uploaded and assigned to users!" -foregroundcolor Green
	write-host ""
}
catch
{ 
	write-host "The script has stopped because there has been an error: "$_ -foregroundcolor Red
}
finally
{
	$mySiteHostWeb.Dispose()
	$mySiteHostSite.Dispose()
}

以上是关于powershell 将图片设置为SharePoint 2010用户配置文件(UPS),图片来自本地路径。的主要内容,如果未能解决你的问题,请参考以下文章

powershell 将执行策略远程签名设置为信任powershell脚本

powershell [PS:设置OWA邮箱策略]命令将特定OWA策略设置为用户#PowerShell#Office365

从 Powershell 调用的 DLL 使用相对于 Powershell 安装目录的路径。如何将其设置为其他内容?

如何使用powershell将监视器超时设置为“从不”

Powershell 将用户帐户密码设置为永不过期

powershell 将AMP优先级设置为指定值。