kennysarmy Posted February 10, 2021 Posted February 10, 2021 I've been asked to reset everyone's photos by SMT so that they all just show initials again. I've run the command : Set-OwaMailboxPolicy OwaMailboxPolicy-Default -SetPhotoEnabled $false Which I believe stops the end-users changing their photos. I then followed further from this guide: https://www.codetwo.com/admins-blog/prevent-users-from-changing-profile-photos-microsoft-365/ To change the SharePoint Online profile policy! I then found this script to reset all the user photos: $Users = Get-AzureADUser | Where {$_.UserType -eq 'Member' -and $_.AssignedLicenses -ne $null} foreach ($user in $Users) {Remove-UserPhoto -Identity $user.UserPrincipalName -Confirm:$false} This was all done over an hour ago. If I check a user in "Microsoft 365 admin center" or "https://outlook.office.com/people/" or Teams admin - there are still users with a profile photo showing! I reset a few manually using this command: Remove-UserPhoto -Identity "" And they seem to have been reset in all but "People" Q. Does it just take a long time to happen? Q. Is there any other way to remove everyone's profile photo and reset to default?
Boredguy Posted February 10, 2021 Posted February 10, 2021 it can take up to 24 hours for changes to take effect, as some of it does not get processed until the address book sync takes place we've found 1
psydii Posted February 10, 2021 Posted February 10, 2021 It takes even longer (2+ weeks!) for Teams clients to sync up too.
kennysarmy Posted February 10, 2021 Author Posted February 10, 2021 It takes even longer (2+ weeks!) for Teams clients to sync up too. Seriously?
Boredguy Posted February 10, 2021 Posted February 10, 2021 When we did it for one of the MAT schools in lockdown 1, it took effect in Teams after a weekend had pasted, so not as bad as 2 weeks. I normally allow at least 48 hours for changes to appear in Teams from 365 1
free780 Posted February 10, 2021 Posted February 10, 2021 Photos are not a priority for Microsoft so the workload isn't given a priority. Mine doesn't work in Edge but works. In everything else.
DaveTheTech Posted February 10, 2021 Posted February 10, 2021 (edited) Get-AzureAdUser wont get all of your users - its limited to 100. Use -All 1. I would also do as much filtering as you can within that cmdlet, rather than passing everything through to a Where-Object. Only bringing this up as I had to find expired groups. It took half the amount of time if I used -displayStartsWith vs piping that to a Where-Object. I found that their pictures disappeared from the Admin Center straight away. I have heard teams taking weeks as it can cache. Removing any sessions might be the way forward. Edited February 10, 2021 by DaveTheTech
HPlum78 Posted February 10, 2021 Posted February 10, 2021 (edited) The teams client caches the photos so if you want to speed teams up you could kill the cache. Get-ChildItem "C:\Users\*\AppData\Roaming\Microsoft\Teams\*" -directory | Where name -in ('application cache','blob storage','databases','GPUcache','IndexedDB','Local Storage','tmp') | ForEach{Remove-Item $_.FullName -Recurse -Force} That would kill the cache for all users that have logged on to a work station and used the teams Client. I would also (I know that the above don't follow this) but ditch the foreach and use users.foreach instead as the performance difference is massive... I have posted about this very thing hunt them out if your interested. Edited February 10, 2021 by HPlum78 1
kennysarmy Posted February 12, 2021 Author Posted February 12, 2021 The teams client caches the photos so if you want to speed teams up you could kill the cache. Get-ChildItem "C:\Users\*\AppData\Roaming\Microsoft\Teams\*" -directory | Where name -in ('application cache','blob storage','databases','GPUcache','IndexedDB','Local Storage','tmp') | ForEach{Remove-Item $_.FullName -Recurse -Force} That would kill the cache for all users that have logged on to a work station and used the teams Client. I would also (I know that the above don't follow this) but ditch the foreach and use users.foreach instead as the performance difference is massive... I have posted about this very thing hunt them out if your interested. Hi, If I replace foreach with users.foreach the script no longer works, was there another change to the script that would be required? Thanks.
kennysarmy Posted February 12, 2021 Author Posted February 12, 2021 I've created a CSV file of all users who have a photo: CSV looks like: users 8122 7846 7941 $users = Import-Csv D:\users2.csv foreach ($user in $Users) {Remove-UserPhoto -Identity $user -Confirm:$false} Can anyone advise why this would give this error: Cannot process argument transformation on parameter 'Identity'. Cannot convert value "@{users=8122}" to type "Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter". Error: "Cannot convert the "@{users=8122}" value of type "Deserialized.System.Management.Automation.PSCustomObject" to type "Microsoft.Exchange.Configuration.Tasks.MailboxIdParameter"." + CategoryInfo : InvalidData: ( [Remove-UserPhoto], ParameterBindin...mationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,Remove-UserPhoto + PSComputerName : outlook.office365.com If I run the code: Remove-UserPhoto -identity "8122" It works!
psydii Posted February 12, 2021 Posted February 12, 2021 try something like: $userstxt = Import-Csv users.csv $i=0 foreach ($user in $Userstxt) { remove-userphoto -identity $user[$i].users -whatif $i=$i++ }
DaveTheTech Posted February 12, 2021 Posted February 12, 2021 Not too sure what the 8122 could be picking up. Your CSV needs to contain something that can be used as an objectID either their samaccountname or userprincipalname. import-csv .\mycsv.csv | % {remove-userphoto $_.UPN} Where UPN is a column header. % is short hand for For-Each. I usually grab things straight from AD. Remove-UserPhoto can take a pipeline argument (if they dont, then you can get around it by using a for-each block): get-aduser -searchbase "ou=students, ou=users, dc=school, dc=com" -filter * | remove-userphoto
kennysarmy Posted February 17, 2021 Author Posted February 17, 2021 Not too sure what the 8122 could be picking up. Your CSV needs to contain something that can be used as an objectID either their samaccountname or userprincipalname. import-csv .\mycsv.csv | % {remove-userphoto $_.UPN} Where UPN is a column header. % is short hand for For-Each. I usually grab things straight from AD. Remove-UserPhoto can take a pipeline argument (if they dont, then you can get around it by using a for-each block): get-aduser -searchbase "ou=students, ou=users, dc=school, dc=com" -filter * | remove-userphoto So I tried : import-csv D:\upn.csv | % {remove-userphoto $_.users} with upn.csv like: UPN [email protected] [email protected] etc Failed with : Cannot bind argument to parameter 'Identity' because it is null. + CategoryInfo : InvalidData: ( [Remove-UserPhoto], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Remove-UserPhoto + PSComputerName : outlook.office365.com
kennysarmy Posted February 17, 2021 Author Posted February 17, 2021 Not too sure what the 8122 could be picking up. Your CSV needs to contain something that can be used as an objectID either their samaccountname or userprincipalname. import-csv .\mycsv.csv | % {remove-userphoto $_.UPN} Where UPN is a column header. % is short hand for For-Each. I usually grab things straight from AD. Remove-UserPhoto can take a pipeline argument (if they dont, then you can get around it by using a for-each block): get-aduser -searchbase "ou=students, ou=users, dc=school, dc=com" -filter * | remove-userphoto If I try the second option the results are: The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input. + CategoryInfo : InvalidArgument: (CN=7755,OU=9,OU...iculum,DC=local:PSObject) [Remove-UserPhoto], ParameterBindingException + FullyQualifiedErrorId : InputObjectNotBound,Remove-UserPhoto + PSComputerName : outlook.office365.com
DaveTheTech Posted February 17, 2021 Posted February 17, 2021 The first error, "..Identity because it is null" - is users a header within your csv? Anything after $_. should be a header within the csv. The second, is where remove-userphoto doesnt accept a pipeline - it needs to be called using a for-each loop. Hopefully double checking that the header name matches up with the one used in the PowerShell should work.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now