Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using Set-UserPhoto to upload user photos to EXO/SPO
# UPDATE THESE VARIABLES
$userDomain = "@tenant.onmicrosoft.com"
$photoFolderURL = "C:\Users\paul.ryan1\Desktop\people\"
$data = @(
@{
User = "alex.law" + $userDomain;
PictureURL = "cast-aaron-j-albano.jpg";
},
@{
User = "david.bowman" + $userDomain;
PictureURL = "cast-richard-todd-adams.jpg";
},
@{
User = "matthew.holden" + $userDomain;
PictureURL = "cast-quentin-earl-darrington.jpg";
},
@{
User = "alex.dorrian" + $userDomain;
PictureURL = "cast-christopher-gurr.jpg";
},
@{
User = "catherine.conroy" + $userDomain;
PictureURL = "cast-emily-tate.jpg";
},
@{
User = "sandy.truong" + $userDomain;
PictureURL = "cast-samantha-sturm.jpg";
},
@{
User = "claire.rowe" + $userDomain;
PictureURL = "cast-lili-elizabeth-froehlich.jpg";
},
@{
User = "christian.ramirez" + $userDomain;
PictureURL = "cast-zachary-downer.jpg";
},
@{
User = "paul.ryan" + $userDomain;
PictureURL = "cast-tyler-hanes.jpg";
},
@{
User = "tim.wallis" + $userDomain;
PictureURL = "cast-colin-cunliffe.jpg";
},
@{
User = "chris.obrien" + $userDomain;
PictureURL = "cast-andy-huntington-jones.jpg";
},
@{
User = "sarah.johnson" + $userDomain;
PictureURL = "cast-claire-rathbun.jpg";
},
@{
User = "ben.athawes" + $userDomain;
PictureURL = "cast-marc-heitzman.jpg";
}
)
# SCRIPT STARTS HERE
$MSOLCred = Get-Credential
$ExSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/?proxymethod=rps -Credential $MSOLCred -Authentication Basic -AllowRedirection
$Import = Import-PSSession $ExSession -CommandName Set-UserPhoto -AllowClobber
Write-Host "Uploading user photos:"
$count = 0
try {
$data | ForEach {
Write-Host "$($_.User)..." -nonewline
try {
Set-UserPhoto -Identity $_.User -PictureData ([System.IO.File]::ReadAllBytes($photoFolderURL + $_.PictureURL)) -Confirm:$false
Write-Host " done" -f green
$count++
}
catch [System.Exception] {
Write-Host " failed!" -f red
}
}
}
finally {
Remove-PSSession $ExSession
}
Write-Host "Successfully uploaded $count photos"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.