We created this PowerShell script to allow organizations to enable/disable the ability for users to edit their Microsoft 365 Profile Photos.
The guide below outlines the steps this script takes, and will help guide you to use the script in your own environment.
There are also extra steps, not included in the script, that will need to be taken for this to be fully implemented. These are also outlined in this guide.
The PowerShell Script Explained
The first thing you need to do is to create a Mailbox Policy that we can use to enable or disable the setting we need to change. To do this we use the code:
New-OwaMailboxPolicy -Name ("Policy Name")
This can be found in the CreatePhotoPolicy Function, once this has been created you need to define whether you are enabling or disabling the picture policy by using one of the following commands:
Set-OwaMailboxPolicy -SetPhotoEnabled $false
Set-OwaMailboxPolicy -SetPhotoEnabled $true
$false disables the picture policy whilst $true enables the policy
Again, these are found in the SetPhotoPolicy, simply remove the starting # from the one you want to action then call the function.
The script connects to Office 365 using the $username and $password variables, simply define these before running the script under the “Variable Definition” section at the very top of the script
Once these have been defined with your O365 Global admin credentials the Connect0365 function with use these to connect to Office365 and also to the MsolService
The next function will use these creds to perform a “Get” for all users within your 365 environment and return these into the script. It will then show a count and display how many accounts there are to process.
Once it has a count it will go through each mailbox individually and apply the OwaMailboxPolicy that we set earlier
Once this has run through all users will either be restricted from setting O365 Profile Photo’s or be allowed to do so, depending on what was defined.
Please contact firstname.lastname@example.org if you have any questions or need any help.