Core.ProfilePictureUploader questions

%3CLINGO-SUB%20id%3D%22lingo-sub-214501%22%20slang%3D%22en-US%22%3ECore.ProfilePictureUploader%20questions%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-214501%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20not%20a%20developer%2C%20but%20more%20of%20a%20System%20Admin%20that%20uses%20scripting%20languages.%20So%20please%20pardon%20me%20if%20the%20answer%20is%20obvious.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20have%20come%20across%20a%20situation%20that%20we%20need%20to%20upload%20User%20Profile%20Pictures%20to%20SharePoint%20Online%2C%20for%20users%20that%20doesn't%20have%20Exchange%20Online%20mailbox%20yet.%20So%20we%20have%20found%20this%20project%20on%20GITHUB%3A%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP%2Ftree%2Fmaster%2FSamples%2FCore.ProfilePictureUploader%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP%2Ftree%2Fmaster%2FSamples%2FCore.ProfilePictureUploader%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20took%20the%20code%20and%20compiled%20it%20and%20it's%20able%20to%20bulk%20upload%20User%20Profile%20Pictures%2C%20but%20we%20ran%20into%20two%20issues.%20When%20I%20tried%20to%20submit%20an%20issue%20on%20GITHUB%2C%20it%20suggested%20me%20to%20use%20this%20community%20instead.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1.%20The%20executable%20file%20requires%20credential%20of%20SPO%20tenant%20admin%20(Office%20365%20admin)%2C%20with%20our%20Security%20Requirement%2C%20all%20O365%20admin%20must%20use%20second%20factor%20authentication%2C%20this%20has%20been%20causing%20the%20executable%20file%20to%20fail%20to%20authenticate%20as%20a%20service%20account%2C%20following%20error%20is%20recorded%3A%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CFONT%20face%3D%22Calibri%22%3EInitializing%20SPO%20web%20service%20https%3A%2F%2F%3CTENANT%3E-admin.sharepoint.com%2F_vti_bin%2Fuserprofileservice.asmx%3C%2FTENANT%3E%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CFONT%20face%3D%22Calibri%22%3EError%20initiating%20connection%20to%20profile%20web%20service%20in%20SPO%20The%20sign-in%20name%20or%20password%20does%20not%20match%20one%20in%20the%20Microsoft%20account%20system.%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CFONT%20face%3D%22Calibri%22%3EProcessing%20finished%20for%200%20user%20profiles%20(or%20so)%3C%2FFONT%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20would%20like%20to%20find%20what%20exact%20permission%20it%20requires%20for%20uploading%20the%20pictures%2C%20without%20having%20to%20use%20O365%20admin%20credential%2C%20which%20is%20an%20obvious%20overkill.%20I've%20tried%20to%20comb%20through%20UnifiedAuditLog%20and%20found%20nothing.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E2.%20There%20are%20scenarios%20that%20the%20on%20premise%20user%20account%20is%20disabled%2C%20as%20such%20we'll%20need%20to%20have%20a%20way%20to%20purge%20their%20user%20profile%20picture%20on%20SharePoint%20Online.%20I've%20tried%20to%20modify%20the%20CSV%20file%20from%3A%3C%2FP%3E%3CP%3EUserPrincipalName%2CSourceUrl%3CBR%20%2F%3Esomeone%40internal.com%2C%3CA%20href%3D%22http%3A%2F%2Fprofilepics.internal.com%2Fffdsasd.jpg%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fprofilepics.internal.com%2Fffdsasd.jpg%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%3A%3C%2FP%3E%3CP%3EUserPrincipalName%2CSourceUrl%3CBR%20%2F%3Esomeone%40internal.com%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20log%20file%20generated%20following%20error%3A%3C%2FP%3E%3CP%3E7%2F10%2F2018%2010%3A00%3A06%20PM%20%3A%20Begin%20processing%20for%20user%20someone%40internal.com%3CBR%20%2F%3E7%2F10%2F2018%2010%3A00%3A06%20PM%20%3A%20Fetching%20source%20image%3A%3CBR%20%2F%3E7%2F10%2F2018%2010%3A00%3A06%20PM%20%3A%20User%20Error%3A%20Error%20fetching%20source%20image%20for%20URL%20Invalid%20URI%3A%20The%20URI%20is%20empty.%3CBR%20%2F%3E7%2F10%2F2018%2010%3A00%3A06%20PM%20%3A%20End%20processing%20for%20user%20someone%40internal.com%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESince%20I'm%20not%20developer%2C%20I%20will%20need%20some%20detailed%20code%20snippet%2C%20and%20which%20section%20of%20the%20existing%20code%20to%20change%20to%20archive%20this%20function.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20feedback%20is%20very%20much%20appreciated%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-216059%22%20slang%3D%22en-US%22%3ERe%3A%20Core.ProfilePictureUploader%20questions%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-216059%22%20slang%3D%22en-US%22%3E%3CP%3EIn%20the%20code%2C%20I%20can%20see%20it's%20using%20Microsoft.SharePoint.Client.File.SaveBinaryDirect%20to%20upload%20Picture%20to%20SharePoint%20Online.%20Is%20there%20a%20function%20I%20can%20call%20to%20Remove%20a%20Profile%20Picture%20instead%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20using%20(Stream%20mediumThumb%20%3D%20ResizeImageSmall(ProfilePicture%2C%20_mediumThumbWidth))%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20if%20(mediumThumb%20!%3D%20null)%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20spImageUrl%20%3D%20string.Format(spPhotoPathTempate%2C%20PictureName%2C%20%22M%22)%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20LogMessage(%22Uploading%20medium%20image%20to%20%22%20%2B%20spImageUrl%2C%20LogLevel.Information)%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Microsoft.SharePoint.Client.File.SaveBinaryDirect(mySiteclientContext%2C%20spImageUrl%2C%20mediumThumb%2C%20true)%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

I'm not a developer, but more of a System Admin that uses scripting languages. So please pardon me if the answer is obvious.

 

We have come across a situation that we need to upload User Profile Pictures to SharePoint Online, for users that doesn't have Exchange Online mailbox yet. So we have found this project on GITHUB: https://github.com/SharePoint/PnP/tree/master/Samples/Core.ProfilePictureUploader

 

We took the code and compiled it and it's able to bulk upload User Profile Pictures, but we ran into two issues. When I tried to submit an issue on GITHUB, it suggested me to use this community instead.

 

1. The executable file requires credential of SPO tenant admin (Office 365 admin), with our Security Requirement, all O365 admin must use second factor authentication, this has been causing the executable file to fail to authenticate as a service account, following error is recorded:

Initializing SPO web service https://<tenant>-admin.sharepoint.com/_vti_bin/userprofileservice.asmx

Error initiating connection to profile web service in SPO The sign-in name or password does not match one in the Microsoft account system.

Processing finished for 0 user profiles (or so)

 

We would like to find what exact permission it requires for uploading the pictures, without having to use O365 admin credential, which is an obvious overkill. I've tried to comb through UnifiedAuditLog and found nothing.

 

2. There are scenarios that the on premise user account is disabled, as such we'll need to have a way to purge their user profile picture on SharePoint Online. I've tried to modify the CSV file from:

UserPrincipalName,SourceUrl
someone@internal.com,http://profilepics.internal.com/ffdsasd.jpg

 

To:

UserPrincipalName,SourceUrl
someone@internal.com,

 

The log file generated following error:

7/10/2018 10:00:06 PM : Begin processing for user someone@internal.com
7/10/2018 10:00:06 PM : Fetching source image:
7/10/2018 10:00:06 PM : User Error: Error fetching source image for URL Invalid URI: The URI is empty.
7/10/2018 10:00:06 PM : End processing for user someone@internal.com

 

Since I'm not developer, I will need some detailed code snippet, and which section of the existing code to change to archive this function. 

 

You feedback is very much appreciated

1 Reply

In the code, I can see it's using Microsoft.SharePoint.Client.File.SaveBinaryDirect to upload Picture to SharePoint Online. Is there a function I can call to Remove a Profile Picture instead?

 

                    using (Stream mediumThumb = ResizeImageSmall(ProfilePicture, _mediumThumbWidth))
                    {
                        if (mediumThumb != null)
                        {
                            spImageUrl = string.Format(spPhotoPathTempate, PictureName, "M");
                            LogMessage("Uploading medium image to " + spImageUrl, LogLevel.Information);
                            Microsoft.SharePoint.Client.File.SaveBinaryDirect(mySiteclientContext, spImageUrl, mediumThumb, true);

                        }
                    }