-
Notifications
You must be signed in to change notification settings - Fork 1
/
Set-UserProfilePhotosInSharePoint.ps1
54 lines (38 loc) · 1.87 KB
/
Set-UserProfilePhotosInSharePoint.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<#
.SYNOPSIS
Add User photos to SharePoint UserProfile.
You will need to connect to your tenant using PNP PowerShell
E.g Connect-PNPOnline -url:https://<tenant>-admin.sharepoint.com -useweblogin
.EXAMPLE
.\Set-UserProfilePhotosInSharePoint.ps1 -Path:'.\data\AzureADUsers.csv' -TenantDomain:'mytenant.onmicrosoft.com'
#>
param(
# The path to the CSV file
[Parameter(Mandatory)][string]$Path,
[Parameter(Mandatory)][string]$TenantDomain
)
$InformationPreference = "Continue";
$ProfilePathFolder = "user photos/profile pictures"
Write-Information -MessageData:"$(Get-Date) Started populating user Profile photos the AD tenant for $TenantDomain."
$tenantName = $TenantDomain.Split('\.')[0]
$mysite = "https://{0}-my.sharepoint.com" -f $tenantName
@($(Import-Csv -path:$Path) | ForEach-Object {
$UserCSV = $PSItem
$DisplayName = $UserCSV.GivenName + ' ' + $UserCSV.Surname
$ImageName = $UserCSV.UserPrincipalName -replace '\.', ' '
$OriginalImageName = "$PSScriptRoot\UserImages\$ImageName.jpg"
$UPN = $UserCSV.UserPrincipalName + '@' + $TenantDomain
if (Test-Path -path:$OriginalImageName) {
$newFileName = $UserCSV.UserPrincipalName + '_' + $TenantDomain -replace '\.', '_'
$LFilePath = "/$ProfilePathFolder/$newFileName" + "_LThumb.jpg"
$Url = $mySite + $LFilePath
Set-PnPUserProfileProperty -Account:$UPN -PropertyName:"PictureURL" -Value:$Url
Set-PnPUserProfileProperty -Account:$UPN -PropertyName:"SPS-PicturePlaceholderState" -Value:0
#Upload To SharePoint Profile
Write-Information -MessageData:"Update User Profile Photos for $DisplayName"
}
else {
Write-Warning -Message:"Unable to find picture for $DisplayName"
}
});
Write-Host "Finished uploading Data at $(Get-Date)"