-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSet-UserPhotosInExchange.ps1
54 lines (38 loc) · 1.6 KB
/
Set-UserPhotosInExchange.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 Exchange, this will allow photos to appear in DELVE and SharePoint.
You will need to run this from Powershell Exchange.
You will need to connect using Connect-EXOPSSession -UserPrincipalName
.EXAMPLE
.\Set-UserPhotosInExchange.ps1 -Path:'.\data\AzureADUsers.csv' -TenantDomain:'mytenant.onmicrosoft.com'
#>
param(
# The path to the CSV file
[Parameter(Mandatory)][string]$Path,
[Parameter(Mandatory)][string]$TenantDomain
)
#Connect using Exchange Online Powershell
$ErrorActionPreference = 'stop'
# Show basic information
$InformationPreference = 'continue'
Write-Information -MessageData:"$(Get-Date) Started populating photos the AD tenant for $TenantDomain."
@($(Import-Csv -path:$Path) | ForEach-Object {
$UserCSV = $PSItem
$DisplayName = $UserCSV.GivenName + ' ' + $UserCSV.Surname
$ImageName = $UserCSV.UserPrincipalName -replace '\.', ' '
try {
Get-User -Identity $UserCSV.UserPrincipalName
}
catch {
Write-Error "Unable to find user $DisplayName"
}
if (Test-Path -path:"$PSScriptRoot\UserImages\$ImageName.jpg") {
Write-Information -MessageData:"Setting UserPhoto for $DisplayName"
$pathtoPicture = "$PSScriptRoot\UserImages\$ImageName.jpg"
Set-UserPhoto -Identity $UserCSV.UserPrincipalName -PictureData ([System.IO.File]::ReadAllBytes($pathtoPicture)) -Confirm:$false
}
else {
Write-Warning -Message:"Unable to find picture for $DisplayName"
}
})
Write-Host "Finished uploading Data at $(Get-Date)"