The code has worked for 3 years. It just started not working with I am using modern authentication:
Connect-ExchangeOnline -Credential $O365Credentials
$Data = Import-Csv d:\files\ePhotoLOGS\ePhoto_Work_File.csv
Import-CSV d:\files\ePhotoLOGS\ePhoto_Work_File2.csv | Foreach-Object{
$PhotePATH="d:\files\photo\$($_.UsrID)\O365\$($_.UsrID).png"
Write-host $PhotePATH
Write-host $($_.UsrID)
Set-UserPhoto $($_.UsrID) -PictureData ([System.IO.File]::ReadAllBytes($PhotePATH))
}
The ReadAllBytes get error:
d:\files\photo\AXSTEVE\O365\AXSTEVE.png
AXSTEVE
Exception calling "ReadAllBytes" with "1" argument(s): "Could not find a part of the path 'd:\files\photo\AXSTEVE\O365\AXSTEVE.png'."
At line:15 char:19
+ Set-UserPhoto $($_.UsrID) -PictureData ([System.IO.File]::ReadAllBy ...
+ ~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DirectoryNotFoundException
The orginall code was a little simpler, but it get the same error:
$photo = [System.IO.File]::ReadAllBytes("d:\files\photo\$($_.UsrID)\O365\$($_.UsrID).png")
Set-UserPhoto -Identity $_.UsrID -PictureData $photo -Confirm:$false -ErrorAction Stop
Is the a way to not get popup on the Set-UserPhoto, to see if want to replace the ephoto. That did not happen until modern authentication all.